javascript - How to click on 'Leave Page' button in the confirmation popup? - Stack Overflow

When I try to close the browser window, I was displayed with a popup saying "This page is asking y

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
Add a ment  | 

2 Answers 2

Reset to default 6

Try 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
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742348219a4426980.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信