Selenium chromedriver won't launch URL if another chrome instance is open

16,015

I found a workaround for this issue. I noticed that this issue happens because chromedriver will not be able to launch with the same profile if there is another open instance using the same profile. For example, if chrome.exe is already open with the default profile, chromedriver.exe will not be able to launch the default profile because chrome.exe is already open and using the same profile.

To fix this, you will need to create a separate profile for automation by copying the default profile so that chromedriver.exe and chrome.exe don't share the same default profile.

The default chrome profile is in this location:

C:\Users\yourUserName\AppData\Local\Google\Chrome\User Data\

Copy all files from User Data folder to a new folder and call it AutomationProfile

After you copy the files to the new folder then you can use it for your scripts.

        String userProfile= "C:\\Users\\YourUserName\\AppData\\Local\\Google\\Chrome\\AutomationProfile\\";
        ChromeOptions options = new ChromeOptions();
        options.addArguments("user-data-dir="+userProfile);
        options.addArguments("--start-maximized");

        driver = new ChromeDriver(options);

Make sure you use driver.quit() at the end of your test so that you don't keep chromedriver.exe open

Share:
16,015

Related videos on Youtube

SOAlgorithm
Author by

SOAlgorithm

Updated on September 15, 2022

Comments

  • SOAlgorithm
    SOAlgorithm over 1 year

    I tried to load chrome profile using selenium weDriver. The profile loads fine but it failed when it tries to load the URL.

    I noticed that this issue happens when there is another chrome instance open whether or not it was open by webDriver. I have selenium 2.53.1.

    System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("user-data-dir=C:/Users/useName/AppData/Local/Google/Chrome/User Data");
    options.addArguments("--start-maximized");
    driver = new ChromeDriver(options);
    
    driver.get("www.google.com") // here is where it fails. It works fine if I close all chrome browsers before I run the test