C#Selenium Chrome Driver 103.0.5060.5300发行

发布于 2025-02-13 15:59:06 字数 5469 浏览 0 评论 0原文

最近开始与Selenium Chrome Driver遇到问题。这开始发生在6月29日。起初,它给出了超时错误,并且随着一些更改,开始收到“ Chrome不可到达”错误。

我已经阅读了许多先前发布的问题,并尝试了许多不同的解决方案。不幸的是,这些似乎都没有解决这个问题。

通常使用“无头”选项,但是为了进行测试,我将其删除以查看它。 Chrome窗口确实会出现,但不会导航到URL。

我使用的版本是Chrome和Chrome驱动程序上的103.0.5060.5300。这是调用时启动的代码(注意:所有评论的线路都是我尝试过的不同解决方案,但这是直到最近才能使用的原始代码)。

public ChromeHeadless()
        {
            //var service = ChromeDriverService.CreateDefaultService();
            //service.LogPath = "D:\\chromedriver.log";
            //service.EnableVerboseLogging = true;
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
            //chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
            chromeOptions.AddArgument("--headless");
            //chromeOptions.AddArgument("--no-sandbox");
            //chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
            driver = new ChromeDriver(chromeOptions);
            //driver = new ChromeDriver(service, chromeOptions, TimeSpan.FromMinutes(3));
            //driver = new ChromeDriver(service, chromeOptions);
        }

“ no-sandbox”或“ - 毫无疑问”似乎是一种对此问题没有任何影响的常见解决方案。

这是试图导航到URL的代码,而超时设置为120,但通常为60:

private void NavigateToURL(string url)
        {
            if (driver == null) throw new Exception("Please create a new instance, the resources have been disposed.");
            driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 0, Core.Properties.Settings.Default.SeleniumPageLoadTimeout, 0);
            driver.Manage().Timeouts().AsynchronousJavaScript = new TimeSpan(0, 0, 0, Core.Properties.Settings.Default.SeleniumAsyncJSTimeout, 0);
            driver.Navigate().GoToUrl(url);
        }

任何帮助都将受到赞赏。

谢谢你!

编辑:错误日志跟踪:

[INFO]: Starting ChromeDriver 103.0.5060.53 (a1711811edd74ff1cf2150f36ffa3b0dae40b17f-refs/branch-heads/5060@{#853}) on port 56389
[INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[INFO]: [9643e0a93623ae715a18e39a50665f01] COMMAND InitSession {
   "capabilities": {
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {
            "args": [ "--headless", "no-sandbox" ]
         },
         "goog:loggingPrefs": {
            "browser": "ALL"
         },
         "pageLoadStrategy": "normal"
      } ]
   }
}
[INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}
[INFO]: Populating Local State file: {
   "background_mode": {
      "enabled": false
   },
   "ssl": {
      "rev_checking": {
         "enabled": false
      }
   }
}
[INFO]: Cannot switch to US keyboard layout - some keys may be interpreted incorrectly
[INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --headless --log-level=0 --no-first-run --no-sandbox --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Windows\TEMP\scoped_dir6296_1256668697" data:,
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[INFO]: Failed to connect to Chrome. Attempting to kill it.
[INFO]: [9643e0a93623ae715a18e39a50665f01] RESPONSE InitSession ERROR chrome not reachable
[DEBUG]: Log type 'driver' lost 0 entries on destruction
[DEBUG]: Log type 'browser' lost 0 entries on destruction

Recently started getting an issue with Selenium Chrome Driver. This started happening around the 29th of June. At first it was giving a timeout error and with some changes, began receiving "Chrome not reachable" errors.

I've read a lot of the questions previously posted and tried a bunch of different solutions given. None of those seemed to fix the issue unfortunately.

Normally the "--headless" option is used, but for testing I removed that to watch it go through. The chrome window does appear but it won't navigate to the URL.

The version I'm using is 103.0.5060.5300 on Chrome and the Chrome Driver. Here's the code that's being initiated when it gets called (Note: all the commented out lines have been different solutions I've tried, but this was the original code that has been working until recently).

public ChromeHeadless()
        {
            //var service = ChromeDriverService.CreateDefaultService();
            //service.LogPath = "D:\\chromedriver.log";
            //service.EnableVerboseLogging = true;
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.PageLoadStrategy = PageLoadStrategy.Normal;
            //chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
            chromeOptions.AddArgument("--headless");
            //chromeOptions.AddArgument("--no-sandbox");
            //chromeOptions.SetLoggingPreference(LogType.Browser, LogLevel.All);
            driver = new ChromeDriver(chromeOptions);
            //driver = new ChromeDriver(service, chromeOptions, TimeSpan.FromMinutes(3));
            //driver = new ChromeDriver(service, chromeOptions);
        }

The "no-sandbox" or "--no-sandbox" seemed to be a common solutions that didn't have any effect on this issue.

Here is the code that is called when it tries to navigate to the url with the timeouts currently set to 120 but usually 60:

private void NavigateToURL(string url)
        {
            if (driver == null) throw new Exception("Please create a new instance, the resources have been disposed.");
            driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 0, Core.Properties.Settings.Default.SeleniumPageLoadTimeout, 0);
            driver.Manage().Timeouts().AsynchronousJavaScript = new TimeSpan(0, 0, 0, Core.Properties.Settings.Default.SeleniumAsyncJSTimeout, 0);
            driver.Navigate().GoToUrl(url);
        }

Any help is appreciated.

Thank You!

EDIT: Error Log Trace:

[INFO]: Starting ChromeDriver 103.0.5060.53 (a1711811edd74ff1cf2150f36ffa3b0dae40b17f-refs/branch-heads/5060@{#853}) on port 56389
[INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[INFO]: [9643e0a93623ae715a18e39a50665f01] COMMAND InitSession {
   "capabilities": {
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {
            "args": [ "--headless", "no-sandbox" ]
         },
         "goog:loggingPrefs": {
            "browser": "ALL"
         },
         "pageLoadStrategy": "normal"
      } ]
   }
}
[INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}
[INFO]: Populating Local State file: {
   "background_mode": {
      "enabled": false
   },
   "ssl": {
      "rev_checking": {
         "enabled": false
      }
   }
}
[INFO]: Cannot switch to US keyboard layout - some keys may be interpreted incorrectly
[INFO]: Launching chrome: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --headless --log-level=0 --no-first-run --no-sandbox --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Windows\TEMP\scoped_dir6296_1256668697" data:,
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[DEBUG]: DevTools HTTP Request: http://localhost:56392/json/version
[DEBUG]: DevTools HTTP Request failed
[INFO]: Failed to connect to Chrome. Attempting to kill it.
[INFO]: [9643e0a93623ae715a18e39a50665f01] RESPONSE InitSession ERROR chrome not reachable
[DEBUG]: Log type 'driver' lost 0 entries on destruction
[DEBUG]: Log type 'browser' lost 0 entries on destruction

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文