本文介绍了Chrome无法访问Selenium WebDriver错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这个问题;我知道这个问题已经存在,我已经尝试了提到的解决方案,因此用我的配置和代码来询问这个问题.

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/

基本的打开浏览器代码:

Basic Open browser code:

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);

    }
}

但仍然出现以下错误:

 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很难解析本地主机,并且在此期间打印了主机

I found that chromedriver had hard time to resolve localhost and during that it printed

Timed out connecting to Chrome, retrying...

它首先尝试通过ipv6进行连接,然后我想回退到ipv4.因此,对我有用的是通过这种方式更改"localhost"的优先级

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

打开RegEdit,导航到 HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ tcpip6 \ Parameters 创建DisabledComponents DWORD注册表值,将其值设置为20 (十六进制). src

Open RegEdit, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tcpip6\Parameters Create DisabledComponents DWORD registry value, set its value to 20 (Hexadecimal). src

这篇关于Chrome无法访问Selenium WebDriver错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 08:36