繁体   English   中英

用Nightwatch.js切换到一个框架

[英]switch to a frame with Nightwatch.js

我正在测试的UI正在使用iframe。 我试图通过“.frame(0)”调用切换到iframe。

module.exports = {
    "test" : function (browser) {
    browser
        .url("my_url")
        .waitForElementVisible(".frame-application-scroll-wrapper", 30000)
        .frame(0)
        .waitForElementPresent("#page-content", 30000)
        .end();
    }
};

但是,#page-content永远不会被看到,这让我觉得更改帧命令不起作用(但是也没有返回错误)。

有任何想法吗?

谢谢,保罗

正如Neoaptt所说(谢谢!),问题是iframe元素要么不存在,要么没有加载。 添加暂停解决了我的问题。

顺便说一下,如果要退出所选框架,则应使用“.frame(null)”

module.exports = {
    "test" : function (browser) {
    browser
        .url("my_url")
        .waitForElementVisible(".frame-application-scroll-wrapper", 30000)
        // give time to the iframe to be available
        .pause(5000)
        .frame(0)
                .waitForElementPresent("#page-content", 30000)
                .frame(null)
         // we are now back to the main page
         // ... more code here ...
         .end();
    }
};

还有助于我调试的是使用--verbose选项,例如:

nightwatch -t tests/test4.js --verbose

这将在您的终端中显示nodejs和selenium之间交换的所有数据。

谢谢,保罗

最新版本的.frameParent().frameParent()而不是.frameParent() .frame(null)来回到父文档,以防万一其他人发现这篇文章:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM