在写selenium的时候,发现很简单的case也报错
package com.lv.test; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Orders { private WebDriver driver = new ChromeDriver(); String orderUrl="http://www.baidu.com"; @Test public void OrdersPage(){ driver.get(orderUrl); System.out.println(driver.getTitle()); driver.quit(); }}
org.openqa.selenium.WebDriverException: unknown error: Runtime.executionContextCreated has invalid ‘context‘: {"auxData":{"frameId":"15372.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=57.0.2987.110)
(Driver info: chromedriver=2.7.236900,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 184 milliseconds
Build info: version: ‘2.26.0‘, revision: ‘18041‘, time: ‘2012-11-01 19:33:38‘
System info: os.name: ‘Windows 7‘, os.arch: ‘amd64‘, os.version: ‘6.1‘, java.version: ‘1.8.0_20‘
Driver info: driver.version: RemoteWebDriver
Session ID: 0db0541b1e8337218da90c01bd25804b
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:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:531)
at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:275)
at com.lvmama.test.Orders.OrdersPage(Orders.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
百度后知道这是由于Chrome和chromeDriver的不匹配造成的
然后就查到Chrome和chromeDriver的对应关系如下,以供参考
下面这部分英文的转载自:http://blog.csdn.net/goblinintree/article/details/47335563;感谢作者!
----------ChromeDriver v2.15 (2015-03-26)----------
Supports Chrome v40-43
----------ChromeDriver v2.14 (2015-01-28)----------
Supports Chrome v39-42
Resolved issue 537: Manually clicking on javascript alert
causes chromedriver to return UnexpectedAlertPresentException for all
subsequent calls [Pri-3]
Resolved issue 1: Implement /sessions command [Pri-3]
Resolved issue 975: driver.findElements(By.id(".."))
not working correctly when id contains semicolon []
Resolved issue 852: Support shadow dom in chromedriver. []
----------ChromeDriver v2.13 (2014-12-10)----------
Supports Chrome v38-41
Resolved issue 997: Chromedriver times out waiting for
Tracing.end command to respond [OS-All, Pri-0]
Resolved issue 980: GoBack command times out on all platforms
[OS-All, Pri-0]
Resolved issue 978: ChromeDriver port server fails to reserve
port [OS-Linux, Pri-0]
Resolved issue 653: Commands goBack and goForward have race
condition. [Pri-1]
Resolved issue 845: chromedriver fails with "Chrome
version must be >= 31.0.1650.59" on Android 4.4.3 webviews [OS-Android,
Pri-1]
Resolved issue 626: silence chrome logging by default on
windows [Pri-1]
Resolved issue 973: ChromeDriver fails to close DevTools UI
before executing commands [OS-All, Pri-2]
----------ChromeDriver v2.12 (2014-10-27)----------
Supports Chrome v36-40
Resolved issue 946: ChromeDriver can‘t parse short git hashes
from Chrome OS [Pri-0]
Resolved issue 906: Chromedriver cannot be instantiated on
CrOS with **kwargs [OS-Chrome, Pri-1]
Resolved issue 944: When using mobile emulation,
window.screen.height/width doesn‘t reflect phone‘s screen resolution [Pri-1]
Resolved issue 916: Selenium (javascript) fails when switching
to webview window in Chrome apps [Pri-2]
Resolved issue 945: touch events sometimes don‘t work in
mobile emulation mode [Pri-2]
Resolved issue 611: Prefs capability should override custom
user data dir prefs [Pri-3]
Resolved issue 926: Chromedriver memory leak in
devtools_client_impl.cc []
----------ChromeDriver v2.11 (2014-10-07)----------
Supports Chrome v36-40
Resolved issue 815: testShouldHandleNewWindowLoadingProperly
fails on ToT builds [OS-All, Pri-0]
Resolved issue 908: No way to exclude switches on Android
[OS-Android, Pri-0]
Resolved issue 868:
SelectElementHandlingTest.testShouldBeAbleToSelectMoreThanOneOptionFromASelectWhichAllowsMultipleChoices
failing [OS-All, Pri-0]
Resolved issue 399: Extend ChromeDriver capabilities to cover
mobile emulation tools in Chrome DevTools [Pri-1, Type-Enhancement]
Resolved issue 906: Chromedriver cannot be instantiated on
CrOS with **kwargs [OS-Chrome, Pri-1]
Resolved issue 776: ChromeDriver does not accept extensions
of zip file format any more [OS-All, Pri-2]
Resolved issue 799: Chrome starts with message "You are
using an unsupported command-line flag: --ignore-certifcate-errors. Stability
and security will suffer." [OS-All, Pri-3]
----------ChromeDriver v2.10 (2014-05-01)----------
Supports Chrome v33-36
Resolved issue 780: Deny remote connections unless
--whitelisted-ips is passed. [Pri-0]
Resolved issue 698: implement touch flick command on Android
[Pri-1]
Resolved issue 760: Implement command to switch to parent
frame [Pri-1]
Resolved issue 152: Support --version switch [Pri-3]
----------ChromeDriver v2.9 (2014-01-31)----------
Supports Chrome v31-34
Resolved issue 665: Use /data/local/tmp for command line
flags on user builds [OS-Android, Pri-0]
Resolved issue 696: Return window handle to App window (like
Google Keep) in command driver.getWindowHandles [Pri-0]
Resolved issue 694: Update
http://chromedriver.storage.googleapis.com/LATEST_RELEASE for users to query
for latest release and do automatic update in script [Pri-0]
Resolved issue 690: Fix clicking on Map Area [Pri-0]
Resolved issue 454: chromedriver didn‘t support Debian 7
[Pri-0]
Resolved issue 638: chomedriver.exe 2.6 to 2.8 built on Win7
build bot always produce empty chromedriver.log on local windows machine.
[Pri-0]
Resolved issue 672: Wait 60 seconds for chrome to start up on
all OS and 30 seconds for chrome shutdown on Mac and Linux. [Pri-0]
Resolved issue 660: Port used for android adb forward leaks.
[Pri-0]
Resolved issue 676: LaunchApp method for launching Chrome
apps using their ID [OS-All, Pri-0]
----------ChromeDriver v2.8 (2013-12-16)----------
Supports Chrome v30-33
Resolved issue 638: Chomedriver 2.7, logging still broken.
[Pri-0]
Resolved issue 507: Cookie creation - Domain getting prefixed
with a period "." [Pri-0]
Resolved issue 516: Extensions with
_generated_background_page no longer loading in 2.3 [Pri-0]
Resolved issue 405: Can‘t type some non-ascii characters
[OS-Windows, Pri-0]
Resolved issue 627: With a keyboard layout != us send_keys
does not send some digits characters (0, 2, 7, 9 ) [OS-Linux, Pri-0]
----------ChromeDriver v2.7 (2013-11-22)----------
Supports Chrome v30-33
Resolved issue 615: ChromeDriver doesn‘t work well with auto
detect proxy settings [OS-Windows, Pri-0]
Resolved issue 614: Implement new redirectionless /session
command [Pri-0]
Resolved issue 625: logging broken on windows [Pri-0]
Resolved issue 573: chromedriver crashes on windows
occasionally [OS-Windows, Pri-1]
----------ChromeDriver v2.6 (2013-11-04)----------
Supports Chrome v29-32
Resolved issue 599: Chromedriver failes after MacOS X
Mavericks upgrade [OS-Mac, Pri-0, Type-Defect]
Resolved issue 585: Return user data dir via capabilities []
----------ChromeDriver v2.5 (2013-11-01)----------
Supports Chrome v29-32
Resolved issue 600: Support minidump for chrome crashes on
Linux with a new capability minidump_path. [Pri-0]
Resolved issue 569: A change in blink breaks scrolling an
element into view [Pri-0]
Resolved issue 554: Release notes broken [Pri-0]
Resolved issue 545: hang when debugger is invoked via JS
[Pri-0]
----------ChromeDriver v2.4 (2013-09-30)----------
Supports Chrome v29-32
Resolved issue 444: chromedriver sometimes hangs when
launching chrome (chrome fails to bind to debug port) [Pri-0]
Resolved issue 529: WebDriver clients fail when attempting to
use empty chromeOption binary string [Pri-0]
Resolved issue 536: remote debugging port taken during
startup [Pri-0]
Resolved issue 520: Some commands hangs if the target window
already crashes. []
Resolved issue 519: Support JS heap snapshot []
----------ChromeDriver v2.3 (2013-09-02)----------
Resolved issue 309: Screenshot is blank from an VM instance
without an open RDC connection [Pri-1]
Resolved issue 445: chromedriver crashes when port is in use
[Pri-1]
Resolved issue 461: TouchUp, TouchDown, and TouchMove
commands [OS-All, Pri-1]
Resolved issue 489: No longer using packed extension id when
loading custom extensions [Pri-3]
Resolved issue 491: Extension does not have its _id_ [Pri-3]
Resolved issue 497: unrecognized chrome option:
useExistingBrowser [Pri-3]
----------ChromeDriver v2.2 (2013-08-06)----------
接在来知道了你目前为止所需求的chromeDriver的版本号之后,就去这里http://chromedriver.storage.googleapis.com/index.html下载,这个链接是发现的目前为止下载最快,可以打开,资源最好的。
然后下载下来的是一个压缩包,解压其中的.exe文件后,放到Chrome的安装目录下
我的安装目录是:C:\Program Files (x86)\Google\Chrome\Application
如果你是直接复制替换文件,可能会提醒文件被占用的什么东西,可能是刚才你跑selenium的时候没有写diriver.quit()
(哎,这坑我都能踩,也是醉了,所以说不管写多简单的case都要最后quit一下,别图省事),只需要打开任务管理器,结束chromedriver.exe就好