【发布时间】:2019-04-22 11:44:12
【问题描述】:
这是
下文档位置的标签<iframe height="900" width="100%" src="/attachments/download/Attachment.pdf" title="document"/>
【问题讨论】:
标签: java selenium xpath iframe css-selectors
这是
下文档位置的标签<iframe height="900" width="100%" src="/attachments/download/Attachment.pdf" title="document"/>
【问题讨论】:
标签: java selenium xpath iframe css-selectors
内联框架是一种将文档嵌入 HTML 文档的结构,以便嵌入的数据显示在浏览器窗口的子窗口中。这并不意味着完全包含并且两个文档是独立的,并且它们都被视为完整的文档,而不是将一个视为另一个的一部分。
您可以在Ways to deal with #document under iframe找到详细讨论。
现在根据最佳实践切换到 iframe,您必须:
诱导 WebDriverWait 使所需的框架可用并切换到它,您可以使用以下任一解决方案:
使用cssSelector:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[src='/attachments/download/Attachment.pdf'][title='document']")));
使用xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@src='/attachments/download/Attachment.pdf' and @title='document']")));
切换到正确的<iframe> 后,您可以滚动 以及与<iframe> 中的任何元素交互
【讨论】: