Am using nightwatchjs to automate submission of a support form. Clicking a link using nightwatchjs opens the form page in a new window. How can I set focus on that window? Any help is greatly appreciated.
Use the switchWindow command. https://nightwatchjs.org/api/switchWindow.html
I try to give you a more detailed explanation with examples of code. Currently I use chromedriver 2.43.1
(installed with npm), selenim standalone 3.141.5
and nigtwatch 0.9.21
.
module.exports = {
'Test new tab open': function (browser) {
browser.url('http://localhost:8000')
.click('#a-href-with-target-blank')
// Switch to new tab
browser.window_handles(function (result) {
// 0 == current main window, 1 == new tab
var handle = result.value[1];
browser.switchWindow(handle);
});
// do something
browser.closeWindow(); // Close tab
// Switch to main window
browser.window_handles(function (result) {
// 0 == current main window, 1 == new tab
var handle = result.value[0];
browser.switchWindow(handle);
});
}
};
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With