Selenium:获取chrome没有正确关闭 [英] Selenium: Getting chrome didn't shut down correctly

查看:1526
本文介绍了Selenium:获取chrome没有正确关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在我的selenium框架中重新打开Chrome浏览器时,我没有正确关闭chrome错误消息。

I'm getting the chrome didn't shut down correctly error message when I reopen a chrome browser in my selenium framework.

在框架中我正在打开我的每个测试用例的开头的浏览器实例使用以下代码

In the framework I'm opening the browser instance at the beginning for each of my test case using the below code

if (browserType.equalsIgnoreCase("Chrome")) {
            try {                               
                System.setProperty("webdriver.chrome.driver", curProj+"\\drivers\\chromedriver.exe");
                ChromeOptions options = new ChromeOptions();
                options.setExperimentalOption("useAutomationExtension", false);
                options.addArguments("disable-infobars");
                //options.addArguments("user-data-dir=C:/Users/xw20/AppData/Local/Google/Chrome/User Data");
                options.addArguments(chromeProfile);
                webdriver = new ChromeDriver(options);
                logger.info("getWebDriver - Setting webdriver.chrome.driver system property as: " + System.getProperty("webdriver.chrome.driver"));
            }
            catch(IllegalStateException e) {
                logger.error("The path to the driver executable must be set by the webdriver.chrome.driver system property. ",e.fillInStackTrace());
                throw new IllegalStateException("The path to the driver executable must be set by the webdriver.chrome.driver system property.");
            }

并使用以下代码在最后结束

and closing at the end using the below code

driver.close();
driver.quit();

但是当我为第二个测试用例打开浏览器时,我得到chrome没关闭正确地弹出消息。

But when I open a browser for the second test case I'm getting "chrome didn't shut down correctly" popup message.

我尝试在Chrome配置文件的首选项文件中更新以下但没有运气

I tried updating the below in the Preferences file of chrome profile but no luck

exit_type:Crashed
exited_cleanly:true

配置:

Chrome版本:版本64.0.3282.186(官方版本)(32位)

Chrome Version: Version 64.0.3282.186 (Official Build) (32-bit)

Selenium版本: 3.11.0

推荐答案

根据您的代码,这将是艰难的在不知道框架结构的情况下分析错误 chrome没有正确关闭背后的原因。也许有关如何调用代码块的更多细节(即 main() TestNG )可能对我们有所帮助。

As per your code it would be tough to analyze the reason behind the error chrome didn't shut down correctly without knowing your framework structure. Perhaps a more details about how code block was invoked (i.e. main() or TestNG) would have helped us.

尽管如此仍有一些因素可供查看:

Having said that there still seems some more factors to look at as follows :


  • 如果您正在使用现有的 Chrome个人资料通过 user-data-dir 理想情况下,您应该避免使用 setExperimentalOption addArguments 这些开关进行自定义这些应设置在相应的 Chrome配置文件中。

  • 当您使用现有的 Chrome配置文件时,通过 user-data-dir ,根据文档 ChromeDriver - 适用于Chrome的WebDriver 路径应指向配置文件目录,如下所示:

  • If you are using an existing Chrome Profile through user-data-dir ideally you should avoid the switches setExperimentalOption and addArguments for customization as those should be set within the respective Chrome Profile.
  • As you are using an existing Chrome Profile through user-data-dir as per the documentation ChromeDriver - WebDriver for Chrome the path should point the profile directory as follows :

options.add_argument("user-data-dir=C:/Users/xw20/AppData/Local/Google/Chrome/User Data/Profile 2")


  • 您可以在 如何通过Python打开Chrome配置文件

    这篇关于Selenium:获取chrome没有正确关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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