javascript - 使用 Nightwatch.js 切换到一个框架

标签 javascript iframe nightwatch.js

我正在测试的用户界面使用的是 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 之间交换的所有数据。

谢谢, 保罗

关于javascript - 使用 Nightwatch.js 切换到一个框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27548030/

相关文章:

node.js - 夜巡卡在启动 Selenium 服务器上

javascript - 实现编号方案,如 A,B,C ... AA,AB, ... AAA ...,类似于将数字转换为 radix26

javascript - 本地存储变量被锁定为 false

php - Laravel 拒绝在 iFrame 中显示为 "' X-Frame-Options' to 'SAMEORIGIN'。”

javascript - 在 querySelectorAll 的选择器中使用变量

vue.js - 在 gitlab-ci 中对 VueJS 应用程序进行端到端测试

javascript - js 多个悬停框在同一个框中响应

javascript - jQuery - mouseOver 改变 div

html - IFrame 和框架有什么区别?

javascript - 如何访问另一个html文件中声明的对象?