selenium webdriver:如何单击将类应用于每个按钮的特定按钮。找不到确切的x路径

问题描述 投票:1回答:4

Q。同一类应用于所有“下载”按钮,如何将它们彼此区分开?假设我要点击下载按钮的第三个数字。查找该按钮的xpath。

我已经尝试过了,但这对所有人来说都是普遍的。

//div[@class='statement-download']

enter image description here

enter image description here

    <div class="statement-download">
       <button class="btn btn-sm btn-icon btn-outline btn-default mb-0" type="button">
       <i class="mdi mdi-download m-r-5"></i>
       <span>Download</span>
       </button>
   </div>
selenium selenium-webdriver xpath
4个回答
1
投票

使用父级indexdiv

//div[@class='statement-card'][3]/div[@class='statement-download']

0
投票

对于第三,尝试按照xpath

(//div[@class='statement-download'])[3]

0
投票

您可以使用日期作为起点

date = 'July 2048'
//div[.='{date}']/following-sibling::div[@class='statement-download']

0
投票

这是一种更好的方法,如果您有多个操作,可以使用循环来完成它

        List<WebElement> statementdownload = 
       driver.findElements(By.xpath("//div[@class='statement-download']"));

        for (int i=0;i<statementdownload.size();i++) {
            statementdownload.get(i).click();
            statementdownload.get(i).getText();

           // You can use your condition here

             }
© www.soinside.com 2019 - 2024. All rights reserved.