admin管理员组文章数量:1333433
When I try to close the browser window, I was displayed with a popup saying "This page is asking you to confirm that you want to leave-data you have entered may not be saved." with two buttons "Leave page" and "Stay on Page". I want to click on 'Leave Page'.Please let me know how can I do that. I got an answer, but it is closing the popup.
(( JavascriptExecutor ) webDriver).executeScript( "window.close()" );
Please let me know how to resolve this.
When I try to close the browser window, I was displayed with a popup saying "This page is asking you to confirm that you want to leave-data you have entered may not be saved." with two buttons "Leave page" and "Stay on Page". I want to click on 'Leave Page'.Please let me know how can I do that. I got an answer, but it is closing the popup.
(( JavascriptExecutor ) webDriver).executeScript( "window.close()" );
Please let me know how to resolve this.
Share Improve this question asked Feb 26, 2016 at 9:42 RahulRahul 7593 gold badges22 silver badges47 bronze badges 2- 1 have you try with driver.switchTo().alert().accept(); ,.... it works sometimes – Shubham Jain Commented Feb 26, 2016 at 9:44
- working for me. Thanks!! – Rahul Commented Feb 26, 2016 at 9:51
2 Answers
Reset to default 6Try Below:-
driver.switchTo().alert().accept();
It will handle browser operation like this
If you are looking for a method to call all the time that deals with the alert if it is there and does nothing otherwise:
void handleUnexpectedAlert() {
try {
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (NoAlertPresentException ignore) {
// This is the way to know it wasn't there
}
}
本文标签: javascriptHow to click on 39Leave Page39 button in the confirmation popupStack Overflow
版权声明:本文标题:javascript - How to click on 'Leave Page' button in the confirmation popup? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742348219a2457958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论