gpt4 book ai didi

java - 使用 selenium 网络驱动程序加载 chrome 浏览器的问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:06:44 24 4
gpt4 key购买 nike

我无法在 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

我哪里错了?

谢谢,马诺杰

最佳答案

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

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

When you want to run Chrome on WebDriver for your Mac, then according to according to the site http://code.google.com/p/selenium/wiki/ChromeDriver you will need to specify the path to the browser to the following location: “/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome”.

So the Java code for creating a ChromeDriver instance will be:

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

When trying to run this I got the following exception.

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
...

This I fixed by using the ChromeDriver. Download your version on http://code.google.com/p/chromedriver/downloads/list, unzip it and use it as followed:

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

关于java - 使用 selenium 网络驱动程序加载 chrome 浏览器的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16937220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com