testing - Selenium WebDriver : How to wait for iframes to load completely? 可以点击 iframe 元素文本框 id = “div_4_1_2_1_1-lnk”

标签 testing iframe selenium selenium-webdriver

问题:我正在测试一个带有 iframe 的页面,其内容由 JavaScript 动态生成。我必须等待 iframe 完全加载,以确保我需要的所有元素都存在。

 <iframe frameborder="0" style="border: 0px none; width: 100%; height: 290px; min-width: 0px; min-height: 0px; overflow: auto;" dojoattachpoint="frame" title="Fill Quote" src=" =1&zTaskId=9309&zResetContext=true&coachDebugTrace=none>
   ------------------------------------------------
  <input id="div_4_1_1_1_1_1_2-in" class="p-field span12" type="text">

我尝试过下面的代码,

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 4000);
wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("div_4_1_2_1_1-lnk"))));

但是它不起作用。而这个iframe只动态生成了他的标题

输出:

Nov 22, 2013 2:52:03 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.id: div_4_1_2_1_1-lnk)
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the      remote browser. It may have died.

最佳答案

Selenium 有一个预期条件可以解决您的问题:

ExpectedConditions.frameToBeAvailableAndSwitchToIt(locator)

我建议您阅读此文link还有这个one

关于testing - Selenium WebDriver : How to wait for iframes to load completely? 可以点击 iframe 元素文本框 id = “div_4_1_2_1_1-lnk”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20141164/

相关文章:

firefox - 测试不同版本的非IE浏览器

angular - Jasmine:Angular Typescript 项目中的 "Incomplete: No specs found"

javascript - 在 IE 中使用 Javascript 关闭 Iframe

javascript - 火狐插件 : How to insert an iFrame on page load based on current domain name

C# 在 Chrome Portable 和 driver.Navigate().GoToUrl 中使用 Selenium

java - Action 类不适用于 Selenium 3.5.3

javascript - Modal 打开后点击 onOk 按钮

java - 我如何配置我的 Jenkins 工作以获得测试报告?

Facebook iFrame Canvas 应用程序 PHP session 问题

java - Selenium/WebView 获取被点击的元素