nightwatch: switchWindow not working
var host = 'www.google.com';
module.exports = {
'some test': function(client) {
client
.url(host)
.waitForElementVisible('body', 1000)
.execute(function(newWindow){
window.open(newWindow, null, "height=1024,width=768");
}, [host])
.waitForElementVisible('body', 1000)
.window_handles(function(result) {
var temp = result.value[0];
this.switchWindow(temp);
})
.end();
}
};
Doesn’t work with result.value[0] or result.value[1].
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 41
Thanks a lot!! @ @sirLisko Yes, it is from the configuration!! That is what I run with selenium-server-standalone-3.13.0 Running: some test
✔ Element <body> was visible after 31 milliseconds. ✔ Testing if the URL contains “google”. ✔ Testing if the URL contains “twitter”. Error while running “switchWindow” command: “TypeError: client.api[method] is not a function” at NightwatchAPI.<anonymous> (/Users/XXX/XX/test-nightwatch/tests/demo.js:63:22) at process._tickCallback (internal/process/next_tick.js:68:7)
FAILED: 1 errors and 3 passed (2.767s)
Guess what, after updating to selenium-server-standalone-3.14.0, all the tests passed!!
I have created the nightwatch to open the application, click on a help link which opens the user guide. If i open the link myself, userguide opens in new tab, while if nightwatch opens it or if i open from window launched by nightwatch, userguide is opened in new window. Quiet strange.
My main target is to focus on the new window and verify the URL in new window but focus is not going to new window but actions still keep performing on the main window.
I have used switch Window for result.value[1]
@SIJIACAN can you show us some code? I think it’s easier 😅
@sirLisko Do you have any solution? I tried frame and I couldn’t solve it. Or I’m using the wrong frame?
In the callback passed to
window_handlesyou got theresultvariable, if you selectvalue[0]you have the main window.