Selenium ChromeDriver 卡在实例创建上

hii*_*aki 5 c# selenium selenium-chromedriver

我正在尝试使用 Selenium 进行网站自动化。
在无头模式下,一切都运行良好,但我需要看看那里发生了什么。

    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");
    }
Run Code Online (Sandbox Code Playgroud)

我的 Chrome 版本是

Google Chrome   87.0.4280.88 (Official Build) (32-bit) (cohort: Stable)
Run Code Online (Sandbox Code Playgroud)

下载 ChromeDriver https://chromedriver.chromium.org/downloads

ChromeDriver 87.0.4280.88 (chromedriver_win32.zip)
Run Code Online (Sandbox Code Playgroud)

Version 3.141.0
Run Code Online (Sandbox Code Playgroud)

启动程序我得到这个:

在此输入图像描述

Starting ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761}) on port 57644
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

有那么一分钟什么都没有发生,最后我明白了

在此输入图像描述

关于我应该更改哪些内容以使 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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

另外,我添加了更多日志并具有以下内容:

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
Run Code Online (Sandbox Code Playgroud)