1

I have difficult time trying to load multiple chrome profile at the same time, and it always show "unknown error: failed to write prefs file" .I'm using selenium 2.48.2 and Selenium.WebDriver.ChromeDriver 2.20.0.0

    string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
      String chromeLocalAppDataPath = localAppDataPath + @"\Google\Chrome\User Data\Default\";


          var options = new ChromeOptions();
                        options.AddArgument("--no-experiments");
                        options.AddArguments("user-data-dir=" + chromeLocalAppDataPath);
                        options.AddArgument("--disable-translate");
                        options.AddArguments("--start-maximized");
                        //options.AddArgument("--disable-plugins");
                        //options.AddArgument("--disable-extensions");
                        options.AddArgument("--no-default-browser-check");
                        options.AddArgument("--clear-token-service");
                        options.AddArgument("--disable-default-apps");
                        options.AddArgument("--no-displaying-insecure-content");
                        //options.AddArgument("--disable-block-external-urls");
                        options.AddArgument("--disable-bundled-ppapi-flash"); 
            using (abcDataContext db = new abcDataContext())
                        {                    
                                Parallel.ForEach(fixtures, (current) =>
                                {  
                                    using (IWebDriver driver = new ChromeDriver(options))   // fail right here
                                    {
                                        driver.Navigate().GoToUrl("http://google.com");
                                    }
                                });
                                counter++;
                            }
                            while (counter <= fixtures.Count() / 3);
}

UPDATE: using firefoxdriver, it works fine with default profile

FirefoxProfileManager profileManager = new FirefoxProfileManager();
                FirefoxProfile profile = profileManager.GetProfile("default");

Parallel.ForEach(collections, (current) =>
                    {

                        IWebDriver driver = new FirefoxDriver(profile);
                        driver.Navigate().GoToUrl("http://google.com");

                    });
nam vo
  • 3,271
  • 12
  • 49
  • 76

7 Answers7

1

What is "fixtures"? Is this collection thread-safe?

Also, IWebDriver/ChromeDriver is not thread-safe.

You can't perform this operation in Parallel.Foreach loop. You need to either put lock outside this operation, but then it will not improve any performance which you intend by using parallel.Foreach.

bayyinah
  • 139
  • 1
  • 3
  • 12
  • thanks for your info, I did put lock before posting here, yes it's not what I want. Guess I'll try different ways – nam vo Dec 06 '15 at 14:08
  • if I use only using (IWebDriver driver = new ChromeDriver()) it works fine, but if i load chrome with its profile extensions (options) which contains adblock then it shows the error. – nam vo Dec 07 '15 at 03:22
1

Multiple chrome instances cannot use same user-data-dir at same time.

If you want to use same profile, you have to copy the original profile to different temporary location and pass that location as user-data-dir.

srees
  • 276
  • 1
  • 4
1

Another reason for this maybe the profile directory (Here the 'default' directory) is a hidden directory as it was in my case.

Unhide the folder and it may start working again

Nishith Savla
  • 310
  • 2
  • 10
0

According to this link, this is a known issue with newer chrome driver versions. One of the comments made on 21 July says the following:

Exception "unknown error: failed to write prefs file" is thrown when same 
user-data-dir and profile is used by two chrome instances in parallel.
This is reproducible in chromedriver:2.15

I am using chromedriver 2.12.301324 and do not have this problem.

Mauritz Hansen
  • 4,674
  • 3
  • 29
  • 34
0

It's caused by parallel execution of ChromeDriver. Other errors as "failed to write first run file" or "cannot create default profile directory" may happen.

My solution was to specify option user-data-dir. Two concurrent Chromedriver should not use same user data directory.

chromeOptions.AddArgument("--user-data-dir=C:\\tmp\\chromeprofiles\\profile" + someKindOfIdOrIndex);

You can of course change the path for whatever you want :)

Éric Bergeron
  • 620
  • 6
  • 7
0

I cleared the temp folder in C drive, problem resolved.

-1

It is caused because of space issue in C: Drive.

Clear some space in C Drive so that the browser can create temp folders and profiles.

Neels
  • 2,547
  • 6
  • 33
  • 40
randomguy
  • 357
  • 2
  • 9