【发布时间】:2015-06-10 11:46:27
【问题描述】:
我正在为使用 ChromeDriver 的 Google Chrome 版本 42.0.2311.90 m 的在线应用程序运行回归包,并且在尝试将焦点从 iFrame 返回到主屏幕时遇到问题,即在达到代码 driver.switchTo().defaultContent();
这在早期版本的 Chrome 上运行良好,并且在具有 39.x.etc 版本的同事电脑上仍然可以正常运行
有没有人遇到过类似的情况?如果是这样,任何帮助/建议/解决方法将不胜感激。
特定 Java 方法的代码是:
@When("I click the $buttonText button in AllFinanz")
public void clickButtonInAllFinanz(String buttonText) throws InterruptedException {
System.out.println("[TEST] Clicking " + buttonText);
try {
// access inside iframe
WebElement elementFrame = driver.findElement(By.xpath("//iframe[contains(@onload, 'riskAssessmentIframe')]"));
driver.switchTo().frame(elementFrame);
// click the button
WebElement button = driver.findElement(By.xpath("//input[@value='" + buttonText + "']"));
button.click();
// return focus to main window
driver.switchTo().defaultContent();
Thread.sleep(sleepTime*5);
System.out.println("[SUCCESS] Clicked button " + buttonText);
} catch (org.openqa.selenium.NoSuchElementException e) {
System.out.println("[FAILURE] Unable to click button " + buttonText);
} catch (org.openqa.selenium.ElementNotVisibleException e) {
System.out.println("[FAILURE] " + buttonText + " not visible");
}
}
如前所述,一切正常,直到 driver.switchTo().defaultContent();代码行,返回以下错误:
org.openqa.selenium.WebDriverException:未知错误:缺少“id” (会话信息:chrome=42.0.2311.90)(驱动程序信息: chromedriver=2.10.267521,平台=Windows NT 5.1 SP3 x86)(警告: 服务器没有提供任何堆栈跟踪信息)系统信息: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45' 驱动信息: driver.version: RemoteWebDriver
再次感谢任何帮助 - 我已经没有想法重新解决方法,并且在谷歌搜索时找不到任何答案。
谢谢, 巴里。
【问题讨论】:
-
只是为了确定问题的原因,在切换到默认内容之前添加
Thread.sleep(5000)。有什么区别吗? -
嗨,Alecxe,这是我第一次尝试解决方法 - 不幸的是没有奏效。还尝试在切换回默认内容之前再次关注 iFrame,以防它失去焦点……还尝试完全忽略默认开关,以防它自动切换回按钮单击……但这两个都不起作用。它似乎仍然专注于“riskAssessmentIframe”,并且在尝试切换回默认内容时失败。真的很奇怪,它在同事电脑上的旧版 Chrome 上运行良好
-
好的,谢谢。将chromedriver升级到最新版本,selenium升级到2.46怎么样?
标签: java selenium selenium-webdriver selenium-chromedriver