如何判断网页上是否存在 iframe?
Html 标签如下所示
<div class="bluebox">
<div class="title"><span>Preview</span></div>
<div class="content">
<iframe frameborder="0" src="about:blank" style="width:100%;height:488px;border:0 none;" id="previewFrame"></iframe>
</div>
<div class="box_shadow">
<div class="left"></div>
<div class="right"></div>
</div>
</div>
在我的代码中我写的是:
driver.switchTo().frame(driver.findElement(By.id("previewFrame")));
System.out.println("Successfully switched to frame.");
boolean checkStatus = driver.findElement(By.id("previewFrame")).isDisplayed();
错误:找不到 iframe
最佳答案
你可以做类似的事情
boolean isExists = true;
try {
driver.findElement(By.id("previewFrame");
// No exception means frame is present
} catch (NoSuchElementException e) {
// Exception, no such frame is present
isExists = false;
}
关于java - 在网页上搜索 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22928858/