Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 371
Paul Avatar asked Jan 26 '26 17:01

Paul


2 Answers

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

like image 137
Paul Avatar answered Jan 28 '26 05:01

Paul


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 :)

like image 28
Chris Heathwood Avatar answered Jan 28 '26 07:01

Chris Heathwood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!