我正在尝试使用Chrome驱动程序在我的MacBook Pro上进行简单的Selenium示例。
我的Java代码相对简单:
package foobar;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class Test {
public static void main (String args[]) throws MalformedURLException {
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:9515"),DesiredCapabilities.chrome());
driver.get("http://www.google.com");
}
}
我在Java控制台上收到以下错误:
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"E55293B5B5CA0A0B5D8D92156BAC0294","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=65.0.3325.181)
(Driver info: chromedriver=2.9.248307,platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 149 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'BUBBAs-MacBook-Pro.local', ip: 'fe80:0:0:0:81e:75ee:3428:6a72%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.3', java.version: '1.8.0_151'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=/var/folders/g5/zj52b8jx3yl_699rjb3n5fkh0000gn/T/.org.chromium.Chromium.2Fm0pC}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=65.0.3325.181, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 14133de001c084e2d16c0e7772f60e5d
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:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:364)
at foorbar.Test.main(Test.java:21)
我使用以下输出
从我的控制台启动了chrome驱动程序Bubbas-MacBook-Pro:Downloads bubba$ ./chromedriver
Starting ChromeDriver (v2.9.248307) on port 9515
[warn] kq_init: detected broken kqueue; not using.: Undefined error: 0
/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppleGVA/AppleGVA-11.3.7/Sources/Slices/Driver/AVD_loader.cpp: failed to get a service for display 6
现在Chrome的一个实例确实已启动 - 请参阅下面的屏幕截图,但它在URL文本字段中填写了“data:”。
我的OSX uname是:
Darwin Bubbas-MacBook-Pro.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
我用谷歌搜索,但一直在做短暂的任何帮助。
更新
答案 0 :(得分:2)
您使用的是年龄较大的chromedriver
,其回溯至2014年。您需要使用最新的chromedriver
https://chromedriver.storage.googleapis.com/2.37/chromedriver_mac64.zip