首页 > 解决方案 > 选择不是 iframe

问题描述

我有一个要查找的元素:

//div[contains(@class, 'bPageBlock')][.//*[.='Agreement Documents']]//div[@class='pbBody']//tr[contains(@class,'dataRow')]//a[text()='View']

问题是,这找到了两个元素,我只想要一个。一个在 iframe 下,一个不在。如果我想要 iframe 下的那个会很容易。我可以

//iframe///div[contains(@class, 'bPageBlock')][.//*[.='Agreement Documents']]//div[@class='pbBody']//tr[contains(@class,'dataRow')]//a[text()='View']

但是,正如您可能猜到的那样,我想要不在 iframe 下的那个。我不知道如何指定类似 //not iframe// 的内容。即使我可以, // 也会找到比 iframe 更低或更高的东西。

任何关于如何找到不在 iframe 下的建议。除此之外的根源和路径似乎都彼此相同。我尝试了很多不同的东西。

如果您想查看特定的 iframe:

<iframe frameborder="0" id="RLPanelFrame" name="RLPanelFrame" src="/emptyHtmlDoc.html" title="Hidden Frame - Ignore" style="height: 176px;"></iframe>

然后它下面有许多子单元,带有自动生成的无意义的 ID。

我不认为我可以使用 driver.find() 找到每个并获取完整的 xpath 并检查“iframe”,因为 selenium 没有 xpath 提取器。我想对于每一个我都可以继续获得父母,直到我到达 //html 或 //iframe 但这需要很长时间。

有什么建议么?这与 Java 和 Selenium

标签: javaseleniumselenium-webdriverxpathautomated-tests

解决方案


推荐阅读