在Selenium中启动Chrome

时间:2013-09-27 13:24:05

标签: google-chrome selenium-webdriver

所以,我正在尝试在Selenium 2.0中启动简单的Chrome浏览器

这是我的代码示例:

System.setProperty("webdriver.chrome.driver", "Path to\\the chromedriver.exe\\which I downloaded from\\ code.google.com");
WebDriver driver = new ChromeDriver();  
driver.navigate().to("http://www.google.com");

我收到以下错误:

Starting ChromeDriver (v2.3) on port 37625
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: version info not in JSON
  (Driver info: chromedriver=2.3,platform=Windows NT 5.1 SP3 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.89 seconds
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_45'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:161)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
at com.qspiders.seleniumpkg.ChromeDemo.main(ChromeDemo.java:16)

我认为这是因为我的Chrome版本为29.0.1547.76 m

我成功启动并使用Firefox和IE。请帮助我,并提前感谢你。

1 个答案:

答案 0 :(得分:1)

查看您的代码我发现您想要启动chrome驱动程序但是要创建Internet Explorer实例 第二件事,当您提供chrome二进制文件的路径时,请使用单个正斜杠 这应该有效。

System.setProperty("webdriver.chrome.driver", "C:/..../chromedriver.exe");
WebDriver driver = new ChromeDriver();