我正在尝试让Selenium单击一个具有频繁变化的xpath的链接,因此我不能指望通过相对xpath或绝对xpath找到它。我正在处理的元素的页面源看起来像..。
<a href="https://webpage.com"/>
<img align="left" border="0" src="/img/folder.png"/>
<strong>Foobar Folder</strong>
</a>我基本上是试图点击"Foobar文件夹“的链接,基于链接本身的文本,"Foobar文件夹”。有什么建议能最好地做到这一点吗?我正在用Java编写代码。
发布于 2014-12-18 17:05:44
那么,试试下面的代码:
driver.findElement(By.xpath("//*[.='Foobar Folder']")).click();它将单击具有精确的innerHTML/text作为“Foobar文件夹”的元素.
发布于 2014-12-18 17:06:41
类似于:
String path = "//a/strong[contains(text(), 'Foobar Folder')]";
webDriver.findElement(By.xpath(path)).click();发布于 2014-12-18 17:09:18
下面的xpath将找到a标记并单击它。
webDriver.findElement(By.xpath("//strong[.='Foobar Folder']/..")).click();https://stackoverflow.com/questions/27551826
复制相似问题