【问题标题】:#document under iFrame is not loaded via selenium webdriver#iFrame 下的文档不是通过 selenium webdriver 加载的
【发布时间】:2021-10-27 16:03:54
【问题描述】:

我试图遍历本地 .html 文件,其中有一个 iFrame 和下面的#document,当它使用 selenium 通过自动化运行时没有被加载。

通过 selenium 驱动运行:

<iframe id="xxxxx" name="yyyy">
.. Nothing is displaying ..

手动打开html文件或通过浏览器刷新按钮刷新:

<iframe id="xxxxx" name="yyyy">
#document
<html>...</html>

注意:在使用调试模式的同一会话中,如果我们使用浏览器刷新手动加载页面,#document 会被加载,但如果我们在调试模式下按“Step Over”并移动到下一步,那么 #document 会再次执行不见了。

尝试了以下所有页面加载,但结果相同:只要通过驱动程序对象执行任何步骤,iFrame 下的#document 就会丢失。

PFB尝试的页面刷新,

public void driver_refresh() {
        getDriver().navigate().refresh();
        wait_for_element(3);
    }

    public void action_refresh() {
        Actions act = new Actions(getDriver());
        Action a1= act.keyDown(Keys.F5).keyUp(Keys.F5).build();
        a1.perform();
    }

    public void js_refresh() {
        ((JavascriptExecutor) getDriver()).executeScript("history.go(0)");
        wait_for_element(3);
    }

    public void robot_refresh() throws Exception {
        Robot r = new Robot();
        r.keyPress(KeyEvent.VK_CONTROL);
        r.keyPress(KeyEvent.VK_R);
        r.keyRelease(KeyEvent.VK_R);
        r.keyRelease(KeyEvent.VK_CONTROL);
    }

    public void robot_refresh_f5() throws Exception {
        Robot r = new Robot();
        r.keyPress(KeyEvent.VK_F5);
        r.keyRelease(KeyEvent.VK_F5);
        wait_for_element(5);
    }

    public void waitForLoad() {
        new WebDriverWait(getDriver(), 30).until((ExpectedCondition<Boolean>) wd ->
                ((JavascriptExecutor) wd).executeScript("return 
        document.readyState").equals("complete"));
    }

【问题讨论】:

    标签: selenium iframe document


    【解决方案1】:

    全部 - 在我遇到问题之前检查了其他步骤,以查看#document 是否在运行时加载,但事实并非如此,它仍然能够执行这些操作。

    因此,检查了我的完整代码,并且我正在刷新页面,因此页面对象在运行时丢失了,因为我有元素的页面工厂。

    现在删除了中间的页面刷新并在同一个会话中继续 - 虽然 #document 没有加载,但从 selenium webdriver 执行所需的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2016-02-08
      • 2020-02-10
      • 2015-01-02
      相关资源
      最近更新 更多