【发布时间】:2018-03-14 18:43:39
【问题描述】:
我正在开发一个在 UI 中嵌套了 iframe 的应用程序。一些 iframe 在测试执行期间刷新。有什么方法可以模拟使用 Selenium 刷新的 iframe?我曾尝试使用 Javascript 和 WebDriverWait,但没有奏效。
我使用了以下方法:
public static void waitForIframeToLoad(String frameName){
WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameName));
}
public static void refreshIFrameUsingJavaScript(String iFrameName)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(String.format("document.getElementById('{0}').src = " +
"document.getElementById('{0}').src", iFrameName));
}
但是这两种方法都不起作用。我可以使用 driver.switchTo().frame("main").switchTo().frame("framename") 在帧之间切换
框架“主”是父框架,它包含多个子框架。用户单击某个按钮后,子框架会刷新,我需要在子框架刷新后验证子框架中的一些文本。 但是,在子框架刷新后,我无法访问脚本中的任何元素。有没有人在类似的情况下工作过?最好的解决方法是什么?
【问题讨论】:
-
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。见:How to create a Minimal, Complete, and Verifiable example.
标签: javascript java selenium-webdriver