admin管理员组文章数量:1323529
I have a non-angular page where I need to click on 2 links. When clicking on one of the link that automatically opens in a new tab. Now I switch to new tab and set the browser.ignoreSynchronization = false
because the newly opened tab is a angular window; and call one of my test. Once verified. I want to close the current tab and go back to the non-angular page to click on link #2 which would again open in a new tab. I tried window.close
but i am getting window is undefined. I used browser.window and even that is not working. Please advise
element(by.id('trMyUrl'));
browser.getAllWindowHandles().then(function (handles) {
var secondWindowHandle = handles[1];
var firstWindowHandle = handles[0];
browser.switchTo().window(secondWindowHandle).then(function () { //the focus moves on new tab\
browser.ignoreSynchronization = false;
empLogin.test();
window(secondWindowHandle).close()
// window.close()
// browser.close()
// browser.window.close()
})
});
I have a non-angular page where I need to click on 2 links. When clicking on one of the link that automatically opens in a new tab. Now I switch to new tab and set the browser.ignoreSynchronization = false
because the newly opened tab is a angular window; and call one of my test. Once verified. I want to close the current tab and go back to the non-angular page to click on link #2 which would again open in a new tab. I tried window.close
but i am getting window is undefined. I used browser.window and even that is not working. Please advise
element(by.id('trMyUrl'));
browser.getAllWindowHandles().then(function (handles) {
var secondWindowHandle = handles[1];
var firstWindowHandle = handles[0];
browser.switchTo().window(secondWindowHandle).then(function () { //the focus moves on new tab\
browser.ignoreSynchronization = false;
empLogin.test();
window(secondWindowHandle).close()
// window.close()
// browser.close()
// browser.window.close()
})
});
Share
Improve this question
edited Oct 23, 2015 at 9:39
giri-sh
6,9622 gold badges27 silver badges50 bronze badges
asked Sep 10, 2015 at 21:40
user2744620user2744620
4391 gold badge10 silver badges21 bronze badges
1 Answer
Reset to default 6Close your second window that is currently focused on and then switchTo()
previous tab first to perform operations on it. Here's how -
browser.switchTo().window(secondWindowHandle)
.then(function () {
browser.ignoreSynchronization = false;
empLogin.test();
}).then(function(){
browser.close(); //close the current browser
}).then(function(){
browser.switchTo().window(firstWindowHandle) //Switch to previous tab
.then(function(){
//Perform your operations on the first tab
});
});
Hope it helps.
本文标签: javascriptProtractor closing current tabStack Overflow
版权声明:本文标题:javascript - Protractor closing current tab - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742128704a2422060.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论