unknown error: failed to write prefs file for loading multiple chrome profile
unknown error: failed to write prefs file for loading multiple chrome profile
我很难同时加载多个 chrome 配置文件,它总是显示 "unknown error: failed to write prefs file"
.我正在使用 selenium 2.48.2 和 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);
}
更新:使用 firefoxdriver,它在默认配置文件下工作正常
FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("default");
Parallel.ForEach(collections, (current) =>
{
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://google.com");
});
什么是"fixtures"?这个集合是线程安全的吗?
此外,IWebDriver/ChromeDriver 不是 thread-safe。
您不能在 Parallel.Foreach 循环中执行此操作。您需要将锁定放在此操作之外,但它不会提高您使用 parallel.Foreach.
打算的任何性能
多个chrome实例不能同时使用相同的用户数据目录。
如果您想使用相同的配置文件,您必须将原始配置文件复制到不同的临时位置并将该位置作为用户数据目录传递。
根据 this link,这是更新的 chrome 驱动程序版本的已知问题。 7 月 21 日发表的评论之一如下:
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
我正在使用 chrome驱动程序 2.12.301324 并且没有这个问题。
这是因为space C:驱动器的问题。
清除 C 盘中的一些 space,以便浏览器可以创建临时文件夹和配置文件。
这是ChromeDriver并行执行造成的。 "failed to write first run file" 或 "cannot create default profile directory" 等其他错误可能会发生。
我的解决方案是指定选项 user-data-dir。两个并发的 Chromedriver 不应使用相同的用户数据目录。
chromeOptions.AddArgument("--user-data-dir=C:\tmp\chromeprofiles\profile" + someKindOfIdOrIndex);
您当然可以根据需要更改路径:)
我清除了C盘的临时文件夹,问题解决了。
另一个原因可能是配置文件目录(这里是 'default' 目录)是一个隐藏目录,就像我的情况一样。
取消隐藏文件夹,它可能会再次开始工作
我很难同时加载多个 chrome 配置文件,它总是显示 "unknown error: failed to write prefs file" .我正在使用 selenium 2.48.2 和 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);
}
更新:使用 firefoxdriver,它在默认配置文件下工作正常
FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("default");
Parallel.ForEach(collections, (current) =>
{
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://google.com");
});
什么是"fixtures"?这个集合是线程安全的吗?
此外,IWebDriver/ChromeDriver 不是 thread-safe。
您不能在 Parallel.Foreach 循环中执行此操作。您需要将锁定放在此操作之外,但它不会提高您使用 parallel.Foreach.
打算的任何性能多个chrome实例不能同时使用相同的用户数据目录。
如果您想使用相同的配置文件,您必须将原始配置文件复制到不同的临时位置并将该位置作为用户数据目录传递。
根据 this link,这是更新的 chrome 驱动程序版本的已知问题。 7 月 21 日发表的评论之一如下:
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
我正在使用 chrome驱动程序 2.12.301324 并且没有这个问题。
这是因为space C:驱动器的问题。
清除 C 盘中的一些 space,以便浏览器可以创建临时文件夹和配置文件。
这是ChromeDriver并行执行造成的。 "failed to write first run file" 或 "cannot create default profile directory" 等其他错误可能会发生。
我的解决方案是指定选项 user-data-dir。两个并发的 Chromedriver 不应使用相同的用户数据目录。
chromeOptions.AddArgument("--user-data-dir=C:\tmp\chromeprofiles\profile" + someKindOfIdOrIndex);
您当然可以根据需要更改路径:)
我清除了C盘的临时文件夹,问题解决了。
另一个原因可能是配置文件目录(这里是 'default' 目录)是一个隐藏目录,就像我的情况一样。
取消隐藏文件夹,它可能会再次开始工作