简体   繁体   English

如何关闭尝试关闭浏览器后出现的Selenium弹出窗口

[英]How to Close a popup in Selenium that appear after trying to close the browser

I'm facing a problem with my selenium tests. 我的硒测试遇到了问题。 I have a script that do some stuff and then close the browser When i do close the browser there is a popup message (screen shot attached) that I need to accept in order for the browser to close. 我有一个脚本,负责执行一些工作,然后关闭浏览器。当我关闭浏览器时,需要接受一条弹出消息(附有屏幕截图),以便关闭浏览器。 My problem is that I tried many different idea but none worked. 我的问题是我尝试了许多不同的想法,但没有一个奏效。 from switch.accept to dismiss() to javascriptExecutor an no luck. 从switch.accept到dismiss()到javascriptExecutor不走运。 This is the method Im using to close the broswer. 这是Im用于关闭浏览器的方法。 after this method is called then i get the popup than i need to close. 在调用此方法后,我得到的弹出窗口比我需要关闭的要多。

public static void closeDriver() throws InterruptedException{
     if(driver!=null){
        driver.quit();
        driver=null;
        log.info("The Browser was closed successfully");
    }

Your scenario is little bit complex , as after closing the browser you want to interact with pop up. 您的情况有点复杂,因为关闭浏览器后您要与之交互的弹出窗口。

Well your code : 那么你的代码:

if(driver!=null){
        driver.quit();
        driver=null;
        log.info("The Browser was closed successfully");
    }  

your driver instance would be closed after driver.quit(); 您的驱动程序实例将在driver.quit();之后关闭driver.quit(); line. 线。

driver=null;
log.info("The Browser was closed successfully");  

should not be executed at all. 根本不应该执行。

But if there are multiple instances of browser you've opened to do your testing, you may wanna switch to driver.close(); 但是,如果您打开了多个浏览器实例进行测试,则可能要切换到driver.close(); .and then try to handle the alert. 。然后尝试处理警报。

This pop-up cannot be handled with any of selenium commands because it cannot be inspected. 由于无法检查此弹出窗口,因此无法使用任何硒命令来处理。 You will have to use AutoIt script for that. 您将必须使用AutoIt脚本。 See the reference below which is for the authentication popup of browser 请参阅下面的参考,有关浏览器的身份验证弹出窗口

https://stackoverflow.com/a/47175309/7030563 https://stackoverflow.com/a/47175309/7030563

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM