问题
the UI I am testing is using an iframe. I am trying to switch to that iframe with the ".frame(0)" call.
module.exports = {
"test" : function (browser) {
browser
.url("my_url")
.waitForElementVisible(".frame-application-scroll-wrapper", 30000)
.frame(0)
.waitForElementPresent("#page-content", 30000)
.end();
}
};
However, #page-content is never seen which makes me think that the change frame command did not work (but returns no error neither).
Any ideas?
Thanks, Paul
回答1:
as Neoaptt mentioned (Thanks!) the issue was that the iframe element was either not present or not loaded. Adding a pause solved my issue.
By the way, if you want to exit the selected frame you should use ".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();
}
};
What also helped me to debug was to use the --verbose option, for example:
nightwatch -t tests/test4.js --verbose
This will display in your terminal all the data exchanged between nodejs and selenium.
Thanks, Paul
回答2:
Latest version of nightwatch is .frameParent()
instead of .frame(null)
to get back to the parent document, just in case any one else finds this post :)
来源:https://stackoverflow.com/questions/27548030/switch-to-a-frame-with-nightwatch-js