问题: 我不知道如何单击我需要的特定按钮以及如何确保该按钮不突出显示。
1) 在主页上,每个页面都有一个按钮。它们都有自己的关闭/报告按钮。
2)我只需要选择非突出显示的页面,然后单击关闭按钮。
我可以用它来点击按钮,但我不知道它是否突出显示。
By.xpath("//button[@type='button'])[8].click();
我尝试做这样的事情,但没有成功:
By.xpath("//li[@class='media'] and //button[@type='button']").click();
这是每个页面的外观。有些突出显示,有些在类名中。
<li class="media highlighted">
<div class="media-options">
<button type="button" class="close" title="Close page">Delete this page</button>
<button type="button" class="report" title="Report page">Report this page</button>
</div>
<li class="media">
<div class="media-options">
<button type="button" class="close" title="Close page">Delete this page</button>
<button type="button" class="report" title="Report page">Report this page</button>
</div>
最佳答案
删除此按钮:-
driver.findElement(By.xpath("//li[@class='media highlighted']//button[@class='close']"));
对于报告此按钮:-
driver.findElement(By.xpath("//li[@class='media highlighted']//button[@class='report']"));
关于java - Selenium Java |使用嵌套在类中的 xpath 查找/单击按钮时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34506610/