C# Selenium ChromeDriver无法创建实例
我正在尝试使用Selenium实现网站自动化。C# Selenium ChromeDriver无法创建实例,c#,selenium,selenium-chromedriver,C#,Selenium,Selenium Chromedriver,我正在尝试使用Selenium实现网站自动化。 在无头模式下,一切都很完美,但我需要看看那里发生了什么 static void Main(string[] args) { var path = @"C:\qq\ChromeDriver"; var options = new ChromeOptions(); //options.AddArgument("--headless"); //with hea
在无头模式下,一切都很完美,但我需要看看那里发生了什么
static void Main(string[] args) {
var path = @"C:\qq\ChromeDriver";
var options = new ChromeOptions();
//options.AddArgument("--headless"); //with headless no issues
options.AddArgument("--disable-dev-shm-usage"); // overcome limited resource problems
options.AddArgument("start-maximized"); // open Browser in maximized mode
options.AddArgument("disable-infobars"); // disabling infobars
options.AddArgument("--disable-extensions"); // disabling extensions
options.AddArgument("--disable-gpu"); // applicable to windows os only
options.AddArgument("--no-sandbox"); // Bypass OS security model
options.AddArgument("--incognito");
IWebDriver driver = new ChromeDriver(path, options); //execution stucks here
driver.Navigate().GoToUrl("https://google.com");
}
我的Chrome版本是
Google Chrome 87.0.4280.88 (Official Build) (32-bit) (cohort: Stable)
下载色度驱动程序
硒
Version 3.141.0
启动程序时,我得到以下信息:
及
有一分钟什么也没发生,最后我
有什么建议,我应该改变,使ChromeDriver的工作
更新堆栈跟踪:
Unhandled Exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:53801/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
Stack Trace:
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)
at WebDriverAlpha.Program.Main(String[] args) in C:\Users\______\Program.cs:line 26
此外,我还添加了更多日志,并具有以下功能:
DevTools listening on ws://127.0.0.1:55720/devtools/browser/d265469d-9647-4e16-8f77-d2493cc1bf42
[50124:50128:1228/030625.394:ERROR:device_event_log_impl.cc(211)] [03:06:25.393] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.400:ERROR:device_event_log_impl.cc(211)] [03:06:25.395] USB: usb_service_win.cc:352 Could not get child device's service name: Element not found. (0x490)
[50124:50128:1228/030625.401:ERROR:device_event_log_impl.cc(211)] [03:06:25.400] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.401:ERROR:device_event_log_impl.cc(211)] [03:06:25.400] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.401:ERROR:device_event_log_impl.cc(211)] [03:06:25.400] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.402:ERROR:device_event_log_impl.cc(211)] [03:06:25.401] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.446:ERROR:device_event_log_impl.cc(211)] [03:06:25.446] Bluetooth: bluetooth_adapter_winrt.cc:1204 Getting Radio failed. Chrome will be unable to change the power state by itself.
[50124:50128:1228/030625.459:ERROR:device_event_log_impl.cc(211)] [03:06:25.459] Bluetooth: bluetooth_adapter_winrt.cc:1282 OnPoweredRadioAdded(), Number of Powered Radios: 1
[50124:50128:1228/030625.459:ERROR:device_event_log_impl.cc(211)] [03:06:25.459] Bluetooth: bluetooth_adapter_winrt.cc:1297 OnPoweredRadiosEnumerated(), Number of Powered Radios: 1
您是从命令行运行此操作的吗?您以什么用户身份运行命令行应用程序?该用户是否具有打开浏览器的权限?请回答您的问题,并在您的帖子中以纯文本形式包含屏幕截图中的文本。图像很难阅读。@GregBurghardt,这是一个控制台应用程序。没有管理员权限,但是用户有打开浏览器的权限,浏览器只停留在空白的“数据”上,页面注释注释了所有的<代码>加法参数< /代码>行。它有用吗?把这些行一行一行加回去,然后试试看。也许有一种或多种选择造成了问题。@GregBurghardt,完全相同的结果。它只是打开了一个新的空选项卡“data;”,并在60秒后超时崩溃。您是从命令行运行它吗?您以什么用户身份运行命令行应用程序?该用户是否具有打开浏览器的权限?请回答您的问题,并在您的帖子中以纯文本形式包含屏幕截图中的文本。图像很难阅读。@GregBurghardt,这是一个控制台应用程序。没有管理员权限,但是用户有打开浏览器的权限,浏览器只停留在空白的“数据”上,页面注释注释了所有的<代码>加法参数< /代码>行。它有用吗?把这些行一行一行加回去,然后试试看。也许有一种或多种选择造成了问题。@GregBurghardt,完全相同的结果。它只会打开一个新的空选项卡“data;”,并在60秒内超时崩溃。
Unhandled Exception: OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:53801/session timed out after 60 seconds. ---> System.Net.WebException: The request was aborted: The operation has timed out.
Stack Trace:
at System.Net.HttpWebRequest.GetResponse()
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
--- End of inner exception stack trace ---
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory)
at WebDriverAlpha.Program.Main(String[] args) in C:\Users\______\Program.cs:line 26
DevTools listening on ws://127.0.0.1:55720/devtools/browser/d265469d-9647-4e16-8f77-d2493cc1bf42
[50124:50128:1228/030625.394:ERROR:device_event_log_impl.cc(211)] [03:06:25.393] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.400:ERROR:device_event_log_impl.cc(211)] [03:06:25.395] USB: usb_service_win.cc:352 Could not get child device's service name: Element not found. (0x490)
[50124:50128:1228/030625.401:ERROR:device_event_log_impl.cc(211)] [03:06:25.400] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.401:ERROR:device_event_log_impl.cc(211)] [03:06:25.400] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.401:ERROR:device_event_log_impl.cc(211)] [03:06:25.400] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.402:ERROR:device_event_log_impl.cc(211)] [03:06:25.401] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[50124:50128:1228/030625.446:ERROR:device_event_log_impl.cc(211)] [03:06:25.446] Bluetooth: bluetooth_adapter_winrt.cc:1204 Getting Radio failed. Chrome will be unable to change the power state by itself.
[50124:50128:1228/030625.459:ERROR:device_event_log_impl.cc(211)] [03:06:25.459] Bluetooth: bluetooth_adapter_winrt.cc:1282 OnPoweredRadioAdded(), Number of Powered Radios: 1
[50124:50128:1228/030625.459:ERROR:device_event_log_impl.cc(211)] [03:06:25.459] Bluetooth: bluetooth_adapter_winrt.cc:1297 OnPoweredRadiosEnumerated(), Number of Powered Radios: 1