我正在测试的用户界面使用的是 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/