简体   繁体   中英

switch to a frame with Nightwatch.js

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

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

最新版本的.frameParent().frameParent()而不是.frameParent() .frame(null)来回到父文档,以防万一其他人发现这篇文章:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM