我是Selenium WebDriver的新手。我找到了一些示例代码,并对其进行了一些调整以获得我自己的测试程序。我遇到了麻烦!这是程序:
package test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTester {
public static void main(String[] args) {
try {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.oddsportal.com/");
driver.manage().window().maximize();
String str = driver.getCurrentUrl();
System.out.println("The current URL is " + str);
}
catch (Exception ex) {
System.out.println("Encountered exception in SeleniumTester.main() :");
System.out.println(ex.getMessage());
}
}
}
编译好,并开始运行,首先输出一些诊断信息:
"Starting ChromeDriver (v2.9.248315) on port 11716
October 25, 2017 6:11:22 IP.
org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS"
但是,在#34; driver.get(...);"发生异常:
"Encountered exception in SeleniumTester.main() :
unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"8164.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'DESKTOP-47EFBCO', ip: '192.168.43.83', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\Ilkka\AppData\Local\Temp\scoped_dir12200_17489}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=61.0.3163.100, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, cssSelectorsEnabled=true}]
Session ID: 31a4a5806225e18533805ed0fbbca392"
关于无效上下文的事情。这是什么意思?怎么解决?我是否应该使用不同的构造函数来创建ChromeDriver?想法,任何人?
答案 0 :(得分:0)
最有可能的问题是因为chromedriver的旧版本。下载更新版本的chromedriver并尝试提供其路径。
浏览器版本和驱动程序版本兼容性问题可能会导致此问题。 chromedriver page提到了浏览器版本的驱动程序兼容性。例如,截至目前,该页面列出了:
最新发布:ChromeDriver 2.33 支持Chrome v60-62