使用selenium web驱动程序加载chrome浏览器的问题

时间:2013-06-05 10:12:59

标签: java google-chrome

我无法在Chrome浏览器中运行我的测试。我正在使用selenium-java 2.33.0和java进行编码。

以下是步骤

System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
WebDriver driver  = new ChromeDriver();
driver.get("http://www.google.com");

它会打开Chrome浏览器并抛出以下错误。

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException:     Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.32.0', revision: '6c40c187d01409a5dc3b7f8251859150c8af0bcb', time: '2013-04-09 10:39:28'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.4', java.version: '1.6.0_35'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
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.integration.RandomID.main(RandomID.java:14)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.32.0', revision: '6c40c187d01409a5dc3b7f8251859150c8af0bcb', time: '2013-04-09 10:39:28'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.4', java.version: '1.6.0_35'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 6 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:17036/status] to be available after 20018 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
... 8 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
... 9 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 10 more

我哪里错了?

谢谢, 的Manoj

2 个答案:

答案 0 :(得分:23)

请勿使用您浏览互联网的Chrome二进制文件。从Chromedriver website下载,并在代码中指定路径。

此链接更详细地解释了解决方案:http://www.gjdb.nl/?p=214

  

如果您想在适用于Mac的WebDriver上运行Chrome,那么根据网站http://code.google.com/p/selenium/wiki/ChromeDriver,您需要指定浏览器到以下位置的路径:“/ Applications / Google \ Chrome。 app / Contents / MacOS / Google \ Chrome“。

     

因此,用于创建ChromeDriver实例的Java代码将是:

     
System.setProperty("webdriver.chrome.driver", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
driver = new ChromeDriver();
     

尝试运行时,我遇到以下异常。

     
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: '2013-02-27 13:51:26'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.8.3', java.version: '1.6.0_45'
Driver info: driver.version: ChromeDriver
...
     

我使用ChromeDriver修复了这个问题。在http://code.google.com/p/chromedriver/downloads/list下载您的版本,解压缩并按以下方式使用:

     
System.setProperty("webdriver.chrome.driver", "<unzip location>/chromedriver");
driver = new ChromeDriver();

答案 1 :(得分:-1)

在开始搜索中搜索chrome.exe,复制文件位置&amp;把它放在网址中:

System.setProperty("webdriver.chrome.driver", ".....AppData/Local/Google/Chrome/Application/chrome.exe");
WebDriver wcr = new ChromeDriver();