gpt4 book ai didi

java - 在网页上搜索 iframe

转载 作者:行者123 更新时间:2023-12-01 13:10:16 25 4
gpt4 key购买 nike

如何判断网页上是否存在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com