WebDriver异常:未知错误:Runtime.executionContextCreated 具有无效的"上下文":在初始化 Chrome 浏览器时



我正在尝试开始使用硒,并下载了一个chrome驱动程序并放入我的类路径中。我现在只是想获得标题,看看我是否可以让它工作。代码当前如下所示:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Flows {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/mn/Desktop/project/turv/src/main/chromedriver");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://google.dk/";
driver.get(baseUrl);
System.out.println(driver.getTitle());
driver.close();
}
}

我希望我的输出类似于"Google",但我却收到此错误:

Connected to the target VM, address: '127.0.0.1:55299', transport: 'socket'
Starting ChromeDriver (v2.8.241036) on port 2571
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
May 07, 2018 12:12:35 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Disconnected from the target VM, address: '127.0.0.1:55299', transport: 'socket'
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"11895A1B77AC560388AA2919259E1422","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=66.0.3359.139)
(Driver info: chromedriver=2.8.241036,platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'cetreas-MBP', ip: 'fe80:0:0:0:c9e:2c67:1d27:4e0b%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {userDataDir: /var/folders/s7/lv2wt4t15cn...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, javascriptEnabled: true, locationContextEnabled: true, nativeEvents: true, platform: MAC, platformName: MAC, rotatable: false, takesHeapSnapshot: true, takesScreenshot: true, version: 66.0.3359.139, webStorageEnabled: true}
Session ID: ca1f4ba131e73c3d01058bec2b976d22
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:273)
at com.cetrea.flows.Flows.main(Flows.java:15)

我真的无法弄清楚错误试图告诉我什么。是因为我在它完全加载网站之前要求标题吗?我需要在getTitle()之前添加某种waitforit命令吗?

此错误消息...

org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"11895A1B77AC560388AA2919259E1422","isDefault":true},"id":1,"name":"","origin":"://"}

。暗示ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

  • 您正在使用chromedriver= 2.8,这是非常古老的
  • 您正在使用的 chrome=66.0
  • ChromeDriver v2.38的发行说明明确提到了以下内容:

支持铬 v65-67

因此,ChromeDriver版本(v2.8)和Chrome浏览器版本(v66.0)之间存在明显的不匹配。

溶液

  • ChromeDriver升级到当前的ChromeDriver v2.38级别。
  • Chrome 版本保持在Chrome v66.x级别。(根据ChromeDriver v2.38发行说明)
  • 通过IDE清理项目工作中心,并仅使用所需的依赖项重新生成项目。
  • 使用CCleaner工具在执行测试套件之前和之后清除所有操作系统杂务。
  • 如果您的基本 Web 客户端版本太旧,请通过Revo 卸载程序将其卸载,并安装最新的 GA 和已发布版本的Web 客户端
  • 重新启动系统
  • 执行您的@Test
  • 始终在方法中调用driver.quit()tearDown(){}以正常关闭和销毁 Web驱动程序Web 客户端实例。

相关内容

  • 没有找到相关文章

最新更新