Chrome 无法访问 Selenium WebDriver 错误 [英] Chrome not reachable Selenium WebDriver error
问题描述
我正面临这个问题;我知道这个问题已经存在,我已经尝试了提到的解决方案,因此用我的配置和代码询问这个问题.
I am facing this issue; I know this question is already present and I have tried the solutions mentioned hence asking this with my configurations and code.
早期脚本正在运行,但现在它们没有运行所以我尝试制作一个基本的打开浏览器脚本.
Earlier the scripts were running but now they aren't So i tried making a basic open browser script.
Selenium WebDriver 的最新版本:http://selenium-release.storage.googleapis.com/3.5/selenium-java-3.5.0.zip
Latest Version of Selenium WebDriver : http://selenium-release.storage.googleapis.com/3.5/selenium-java-3.5.0.zip
ChromeDriver 的最新版本:http://chromedriver.storage.googleapis.com/index.html?path=2.31/
Latest Version on ChromeDriver : http://chromedriver.storage.googleapis.com/index.html?path=2.31/
基本打开浏览器代码:
package Trial;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Trial_Class {
public static void main(String args[]){
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.youtube.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
但我仍然收到以下错误:
But still I am getting the below error:
Starting ChromeDriver 2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8) on port 43967
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.WebDriverException: chrome not reachable
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.81 seconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'SWATI', ip: '192.168.0.5', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_121'
Driver info: driver.version: ChromeDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24(ProtocolHandshake.java:360)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:363)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:137)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:254)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:178)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:167)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
at Trial.Trial_Class.main(Trial_Class.java:11)
提前致谢.
推荐答案
我发现 chromedriver 很难解析 localhost 并在此期间打印出来
I found that chromedriver had hard time to resolve localhost and during that it printed
Timed out connecting to Chrome, retrying...
它首先尝试通过 ipv6 连接,然后我猜想回退到 ipv4.所以对我有用的是以这种方式更改本地主机"的优先级
It first tried to connect via ipv6 and then I guess fall back to ipv4. So what worked for me was to change the priority of "localhosts" this way
您唯一需要做的就是更改优先级:
The only piece you should need to do is change the priority:
打开 RegEdit,导航到HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServices cpip6Parameters创建 DisabledComponents DWORD 注册表值,将其值设置为 20(十六进制).src
Open RegEdit, navigate to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServices cpip6Parameters Create DisabledComponents DWORD registry value, set its value to 20 (Hexadecimal). src
这篇关于Chrome 无法访问 Selenium WebDriver 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!