switch to a frame with Nightwatch.js

允我心安 提交于 2019-12-07 12:18:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!