简体   繁体   English

无法使用C#在Selenium上使用已保存的配置文件启动Chrome驱动程序

[英]Can't start Chrome Driver with saved profile on Selenium with C#

I wrote a method to start clear Chrome Driver with different parameters, and it works. 我编写了一种使用不同的参数启动清除Chrome驱动程序的方法,并且该方法有效。 But when I was needed to start Chrome with my default profile (with saved cookies) - I wrote this lines of code, it runs browser (and I see my bookmarks, so it runs with cookies), but visual studio sleeps for a minute at return line, and throw me an exception. 但是,当我需要使用默认配置文件(带有保存的Cookie)启动Chrome时-我编写了以下代码行,它运行了浏览器(并且我看到了我的书签,因此它运行了Cookie),但是Visual Studio的睡眠时间为返回行,并抛出异常。 What is the problem here? 这里有什么问题?

public RemoteWebDriver SetDriver(String Browser)
    {
        switch (Browser)
        {
            case "CH":   
                ChromeOptions options = new ChromeOptions();                    
                options.AddArguments("--user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data");
                return new ChromeDriver(options);

在此处输入图片说明

OpenQA.Selenium.WebDriverException was unhandled
HResult=-2146233088
Message=The HTTP request to the remote WebDriver server for URL http://localhost:52036/session timed out after 60 seconds.
Source=WebDriver
StackTrace:
w OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:wiersz 170
w OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:wiersz 121
w OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\DriverServiceCommandExecutor.cs:wiersz 84
w OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:wiersz 1177
w OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:wiersz 1114
w OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:wiersz 141
w OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options) w c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriver.cs:wiersz 76
w AutoLike.Login.SetDriver(String Browser) w d:\users\documents\visual studio 2015\Projects\AutoLike\AutoLike\Login.cs:wiersz 70
w AutoLike.Login..ctor(String Browser, String URL, String DownloadPath) w d:\users\documents\visual studio 2015\Projects\AutoLike\AutoLike\Login.cs:wiersz 32
w AutoLike.Form1.button1_Click(Object sender, EventArgs e) w d:\users\documents\visual studio 2015\Projects\AutoLike\AutoLike\Form1.cs:wiersz 34
w System.Windows.Forms.Control.OnClick(EventArgs e)
w System.Windows.Forms.Button.OnClick(EventArgs e)
w System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
w System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
w System.Windows.Forms.Control.WndProc(Message& m)
w System.Windows.Forms.ButtonBase.WndProc(Message& m)
w System.Windows.Forms.Button.WndProc(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
w System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
w System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
w System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.Run(Form mainForm)
w AutoLike.Program.Main() w d:\users\documents\visual studio 2015\Projects\AutoLike\AutoLike\Program.cs:wiersz 19
w System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
w System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
w System.Threading.ThreadHelper.ThreadStart_Context(Object state)
w System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException: 
HResult=-2146233079
Message=Upłynął limit czasu operacji
Source=System
StackTrace:
w System.Net.HttpWebRequest.GetResponse()
w OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) w c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:wiersz 162

You need to quote the path since it contains a space character: 您需要引用路径,因为它包含空格字符:

options.AddArguments(String.Format(
   "--user-data-dir=\"{0}\"", @"C:\Users\user\AppData\Local\Google\Chrome\User Data"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 chrome驱动程序不会使用给定的配置文件C#启动会话 - chrome driver wont start session with given profile C# C# Selenium 使用不同的用户配置文件启动 Chrome - C# Selenium Start Chrome with Different User Profile 如何使用c#和Selenium chrome驱动程序加载特定的Google Chrome配置文件? - How to load specific google chrome profile using c# & Selenium chrome driver? 打开 Chrome 配置文件 selenium C# 不工作 - Open Chrome profile selenium with C# not working C# Selenium Chrome 驱动程序未等待 - C# Selenium Chrome Driver isnt waiting C#硒中的Chrome驱动程序问题 - Chrome Driver issues in C# selenium Selenium - Visual Studios- C# - 所有(chrome、firefox 和 Internet Explorer)webdrivers 无法启动驱动程序服务 - Selenium - Visual Studios- C# - All (chrome, firefox, and internet explorer) webdrivers unable to start driver service C#Selenium Web驱动程序无法选中复选框 - C# Selenium web driver can't tick a check box 无法在 Selenium 中启动 Chrome 驱动程序 - Can't launch chrome driver in Selenium OpenQA.Selenium.WebDriverException Message=无法在 http://localhost:port/ 上通过 C# 中的 Selenium 使用 ChromeDriver Chrome 启动驱动程序服务 - OpenQA.Selenium.WebDriverException Message=Cannot start the driver service on http://localhost:port/ using ChromeDriver Chrome through Selenium in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM