1
我編寫了一個方法,用不同的參數清除Chrome驅動器,並且它可以正常工作。但是,當我需要使用我的默認配置文件(使用保存的cookie)啓動Chrome時 - 我編寫了這些代碼行,它運行的是瀏覽器(並且我看到了我的書籤,因此它使用Cookie運行),但是visual studio在一分鐘內睡了一會兒返回線路,並拋出一個例外。這裏有什麼問題?用C保存的配置文件無法在硒上保存配置文件啓動Chrome驅動程序#
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
好像不是這種情況,因爲即使有空格字符啓動瀏覽器。現在它沒有: 'System.InvalidOperationException了未處理的HResult = -2146233079 消息=未知錯誤:無法創建默認配置文件目錄 (駕駛員信息:chromedriver = 2.30.477700(0057494ad8732195794a7b32078424f92a5fce41),平臺= Windows NT的6.1.7601 SP1 x86_64) 來源= WebDriver' – pad0n
您需要引用。否則'數據'被認爲是一個額外的參數。此新錯誤表示您提供的路徑不存在,或者您運行代碼的帳戶沒有讀取文件夾的權限。 –
也不適用於我 – r0bb077