Selenium: Getting chrome didn't shut down correctly

后端 未结 3 958
南笙
南笙 2021-01-20 05:44

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

相关标签:
3条回答
  • 2021-01-20 05:50

    Did you set exit_type:Normal, I'm currently doing that before the test start, and or after the test ends and it Works. on C#

     public static void FixChromeSingleProfile(string dataDir)
        {
            FileStream fs = new FileStream(dataDir, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);
            string json = sr.ReadToEnd();
            sr.Close();
            fs.Close();
            dynamic jsonDe = JsonConvert.DeserializeObject(json);
            if (jsonDe.profile.exit_type != "Normal")
            {
                jsonDe.profile.exit_type = "Normal";
                string r = JsonConvert.SerializeObject(jsonDe);
    
                StreamWriter sw = new StreamWriter(dataDir, false);
                sw.Write(r);
                sw.Close();
            }
        }
    
    0 讨论(0)
  • 2021-01-20 05:53

    This solution is in Python and works 100% but you should be able to implement this in Java as well. I just call the close_windows function every time I am finished using Selenium.

    def close_windows():
    
        windows = driver.window_handles
    
        for w in windows:
            driver.switch_to.window(w)
            driver.close()
    
        driver.quit()
    
    close_windows()
    
    0 讨论(0)
  • 2021-01-20 06:12

    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 :

    • 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")
      
    • Here you can find a detailed discussion at How to open a Chrome Profile through Python

    • Avoid using driver.close(); and always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
    • Here you can find a detailed discussion at PhantomJS web driver stays in memory
    • Upgrade JDK to recent levels JDK 8u162.
    • Upgrade Selenium to current levels Version 3.11.0.
    • Upgrade ChromeDriver to current ChromeDriver v2.37 level.
    • Upgrade Chrome version to current Chrome v65.x levels.
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
    • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Execute your @Test.
    0 讨论(0)
提交回复
热议问题