我有这样一个结构

它的视觉效果如何

我试图得到最后一项并点击它,但是第四项被选中了。
driver.findElement(By.xpath(("//*[@id=\"page-body\"]/div/div[2]/ul[last()]"))).click();我如何点击最后一个项目和55?
发布于 2019-03-25 09:29:51
当您使用这样的xpath查找元素时:
driver.findElement(By.xpath(("//*[@id=\"page- body\"]/div/div[2]/ul[last()]"))).click();基本上,您查找的最后一个ul元素是
li元素的容器。因此,您的代码看起来可能如下:
driver.findElement(By.xpath("//div[@class='pagination']/ul/li[last()]")).click();发布于 2019-03-25 10:44:32
"//div[@class="pagination"]/li[not(contains(@class, 'arrow') and last()])]/a"分解:
在具有类分页-> //div[@class="pagination"]的div中
查找没有箭头类-> li[not(contains(@class, 'arrow')的li
并获取最后一个-> and last()]
在这个li里面,寻找一个链接-> /a。
https://sqa.stackexchange.com/questions/38407
复制相似问题