5

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
SOAlgorithm
  • 407
  • 1
  • 5
  • 15
  • That's not possible.But you can tweak around based on your requirement [See this](http://stackoverflow.com/q/27630091/3122133) – Madhan Jul 05 '16 at 05:03

2 Answers2

9

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

SOAlgorithm
  • 407
  • 1
  • 5
  • 15
1

I added the ChromeOption "no-sandbox", and it seemed to help me with a similar issue. Know that this changes how secure your browsing can be. Here's a link that explains it more: https://www.google.com/googlebooks/chrome/med_26.html

var options = new ChromeOptions();
//I had more options added, but this is the example of the argument I referred to
options.AddArgument("no-sandbox");
Devon
  • 160
  • 1
  • 12