如何通过在selenium webdriver中拒绝弹出窗口来关闭浏览器 [英] How to close the browser by rejecting popup window in selenium webdriver

查看:1039
本文介绍了如何通过在selenium webdriver中拒绝弹出窗口来关闭浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试用例,在用户尝试关闭浏览器后的某个页面上登录后,它会显示弹出窗口(警报),询问您可能会丢失数据,您确定要继续吗?两种选择:

点击特定选项,页面将执行操作。



'停留在页面上'不会离开页面并离开页面将关闭浏览器。



现在,当我尝试关闭浏览器时,它不会要求我弹出

  webdriver.close()

关闭浏览器。



如何接受/拒绝弹出窗口,然后基于操作,它应该关闭浏览器?

解决方案

如果我正确理解问题,那么您正试图单击 X 关闭浏览器窗口,从而生成额外的弹出窗口。一世f就是这种情况,您可以尝试执行一些 JavaScript 操作来重新创建场景

 <$ c $(> JavaScriptExecutor)webdriver).executeScript(window.close()); 

而不是 webdriver.close()



注意:写入 Java


更多信息:
使用上面的语法,您只能关闭子选项卡而不是整个浏览器,只要使用 window.open()



I have one test case where after login, on some page when user tries to close the browser, it will show popup windows(alert) asking "you might lose the data, are you sure you want to continue?', with two options:

  1. Leave the page
  2. Stay on page

Clicking on specific option, the page will perform action.

'Stay on page' will not leave the page and Leave the page will close the browser.

Now when I try to close the browser, it doesn't ask me for Popup

webdriver.close() 

closes the browser before.

How can I Accept/Reject popup and then based on action, it should close the browser?

解决方案

If I am understanding the problem correctly, then you are trying to perform a click on X to close the browser window which generates additional pop up. If that's the case, you can try executing some JavaScript action to recreate the scenario

(( JavascriptExecutor ) webdriver).executeScript( "window.close()" );

instead of webdriver.close()

Note: Written in Java

More info: With the syntax above you can only close the child tab not the entire browser only IF it is invoked with window.open()

这篇关于如何通过在selenium webdriver中拒绝弹出窗口来关闭浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆