用Nightwatch.js切换到一个框架

Pau*_*aul 3 javascript iframe 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();
    }
};
Run Code Online (Sandbox Code Playgroud)

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

有任何想法吗?

谢谢,保罗

Pau*_*aul 7

正如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();
    }
};
Run Code Online (Sandbox Code Playgroud)

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

nightwatch -t tests/test4.js --verbose
Run Code Online (Sandbox Code Playgroud)

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

谢谢,保罗