1. 程式人生 > 實用技巧 >Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.

Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.

在使用 webdriver 開啟瀏覽器的時候,丟擲了一個異常:

Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 15911
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Exception 
in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start. Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'USERUQI-HIIH0SU', ip: '10.10.40.23', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '
1.8.0_171' Driver info: driver.version: ChromeDriver at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:202) at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:188) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:
79) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157) at com.pan.spider.spider_business.Test.main(Test.java:31) Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:15911/status] to be available after 20039 ms at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100) at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:197) ... 9 more Caused by: java.util.concurrent.TimeoutException at java.util.concurrent.FutureTask.get(FutureTask.java:205) at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156) at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75) ... 10 more

排查流程:

1:確認瀏覽器版本和chromdriver.exe 版本是否對應,本地瀏覽器版本

訪問:https://npm.taobao.org/mirrors/chromedriver/

下載對應的版本依然報錯,更換方法

2:在瀏覽器訪問http://localhost:15911/status ,有對應的返回值

能夠訪問成功,並沒有超時,懷疑可能是hosts配置有誤

檢視自己的hosts配置檔案,發現有 localhost 對應的IP有兩個,這裡不方便發出圖片,只留下 127.0.0.1 的配置,其他配置刪除,問題解決