使用Selenium WebDriver无法加载Chrome的默认配置文件

4
我正在使用Selenium WebDriver,对需要http认证的页面做一些操作。
我已经在默认配置文件中登录。但是,每次使用Selenium chromedriver都会自动使用新的配置文件,因此我无法通过身份验证阶段。
因此,我想在Chrome的Selenium WebDriver上使用我的默认配置文件(带有帐户登录信息)。
即使我使用以下代码,也似乎无法将默认配置文件加载到Chrome中:
ChromeOptions options = new ChromeOptions();

options.AddArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data/Default");   


IWebDriver driver = new ChromeDriver(@"C:\Users\Lawrence\Desktop\selenium-dotnet-2.33.0\net40",options);

有需要帮忙的吗? =)

请参见以下链接:https://dev59.com/zIbca4cB1Zd3GeqPUlcc。该链接涉及如何在不同的ChromeDriver实例中使用相同的Chrome配置文件会话。 - William
1个回答

5

尝试在Chrome开关之前添加“--”,并从路径中删除Default,如果需要,请转义斜杠。

options.AddArguments("--user-data-dir=C:\\Users\\user_name\\AppData\\Local\\Google\\Chrome\\User Data");

嗨,我尝试在Chrome开关前添加“--”,但遗憾的是它没有起作用。 - Lawrence Wong
嗨,@user1177637,我刚试了更新的代码。它仍然无法工作。还有更多建议吗? - Lawrence Wong
@LawrenceWong:请解释一下not working是什么意思?同时确保你的路径是正确的。 - Yi Zeng
嗨user1177636,我刚意识到我忘记把user_name改成我的个人资料名称了。谢谢!现在它可以工作了。=) - Lawrence Wong
嗨@YiZeng,我试过了,Chrome打开了用户配置文件,但是出现了这个错误{"The HTTP request to the remote WebDriver server for URL http://localhost:52408/session timed out after 60 seconds."}。 - Gokul
@Gokul:你好。这个答案是4年前发布的,ChromDriver已经有了很大的变化。也许可以创建一个小演示来重现您的问题,并在此处获得帮助 https://sites.google.com/a/chromium.org/chromedriver/help - Yi Zeng

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接