【问题标题】:Refreshing nested Iframe in the Selenium script在 Selenium 脚本中刷新嵌套的 iframe
【发布时间】: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") 在帧之间切换

框架“主”是父框架,它包含多个子框架。用户单击某个按钮后,子框架会刷新,我需要在子框架刷新后验证子框架中的一些文本。 但是,在子框架刷新后,我无法访问脚本中的任何元素。有没有人在类似的情况下工作过?最好的解决方法是什么?

【问题讨论】:

标签: javascript java selenium-webdriver


【解决方案1】:

当您刷新时,您的 webelement 对象变得“陈旧”并且不再是相同的对象。您需要(重新)实例化您的 webelement 对象。您甚至可能需要先切换回父框架,然后转到子框架,最后实例化您的 web 元素对象。

【讨论】:

    猜你喜欢
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 2014-09-01
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多