Selenium Webdriver通信错误

我正在做一个java项目,它使用selenium web驱动程序自动在网站上执行任务,但是会出错 .

设置 System.setProperty("webdriver.chrome.driver","path to chrome driver");

有这种方法

public boolean openBrowserAndLoadUrl(String url) {          
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-extensions","--start-maximized");
        WebDriver driver = new ChromeDriver(options);
        if(driver==null)
            return false;
        driver.get("https://www.google.co.in");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        return true;
}

的pom.xml

<org.seleniumhq-version>2.53.1</org.seleniumhq-version>

<!-- Selenium -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>${org.seleniumhq-version}</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.23</version>
    </dependency>

“驱动程序”变量已初始化,Google Chrome已打开 . Eclipse调试显示异常发生在这里 driver.get("https://www.google.co.in");

两次出现两种类型的错误!两个堆栈跟踪如下所示 .

org.openqa.selenium.remote.UnreachableBrowserException:与远程浏览器通信时出错 . 它可能已经死了 . 构建信息:版本: '2.53.1',修订版: 'a36b8b1cd5757287168e54b817830adce9b0158d',时间: '二零一六年六月三十零日19时26分09秒' 系统信息:主机: 'FMS-dev的' IP: '192.168.1.56', os.name:'Windows 8.1',os.arch:'amd64',os.version:'6.3',java.version:'1.8.0_101'驱动程序信息:driver.version:RemoteWebDriver功能[{applicationCacheEnabled = false,可旋转=假,铬= {userDataDir = C:\用户\ FMS \应用程序数据\本地的\ Temp \ scoped_dir3000_27723},takesHeapSnapshot = TRUE,databaseEnabled =假,handlesAlerts = TRUE,版本= 54.0.2840.71,平台= WIN8_1,browserConnectionEnabled =假, nativeEvents = true,acceptSslCerts = true,locationContextEnabled = true,webStorageEnabled = true,browserName = chrome,takesScreenshot = true,javascriptEnabled = true,cssSelectorsEnabled = true}]会话ID:05d03919d730cf29cb2267aba8f0de45 at org.openqa.selenium.remote.RemoteWebDriver.execute( RemoteWebDriver.java:665)org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:316)

后来我收到了这个错误

org.openqa.selenium.WebDriverException:未知错误:Runtime.executionContextCreated具有无效的'context':{“auxData”:{“frameId”:“4492.1”,“isDefault”:true},“id”:1,“name “:”“,”origin“:”://“}(会话信息:chrome = 54.0.2840.71)(驱动程序信息:chromedriver = 2.9.248315,platform = Windows NT 6.3 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:39毫秒构建信息:版本:'2.53.1',修订版:'a36b8b1cd5757287168e54b817830adce9b0158d',时间:'2016-06-30 19:26:09'系统信息:主机:'dev- pc',ip:'192.168.1.56',os.name:'Windows 8.1',os.arch:'amd64',os.version:'6.3',java.version:'1.8.0_101'驱动程序信息:org . openqa.selenium.chrome.ChromeDriver能力[{applicationCacheEnabled =假,可旋转=假,铬= {userDataDir = C:\用户\ dev的\应用程序数据\本地\ TEMP \ scoped_dir960_31279},takesHeapSnapshot =真,databaseEnabled =假,handlesAlerts =真,version = 54.0.2840.71,platform = WIN8_1,browserConnectionEnabled = false,nativeEvents =真,acceptSslCerts =真,locationContextEnabled =真,webStorageEnabled =真,browserName =铬,takesScreenshot =真,javascriptEnabled =真,cssSelectorsEnabled =真}]会话ID:a1f32c762f3525f55845afd4ab824af5在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)在阳光下 . reflect.NativeConstructorAccessorImpl.newInstance(未知来源)在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知来源)在java.lang.reflect.Constructor.newInstance(未知来源)在org.openqa.selenium.remote.ErrorHandler.createThrowable(的ErrorHandler . 的java:206)在org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)在org.openqa.selenium.remote .RemoteWebDriver.get(RemoteWebDriver.java:316)

在进一步的研究中,我知道很多人有这个问题,但除了 incompatible version 问题我没有得到任何解决方案 . 但我正在使用下载的chromedriver.exe

Also, earlier all the selenium steps had succeeded with this chrome driver and same selenium version. . 不知道为什么会发生这种情况!请帮忙 .

回答(1)

2 years ago

安装在Windows系统中的Google Chrome可能已自动更新 .
您可以从chrome驱动程序网站下载最新的驱动程序 .