com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java)与ChromeDriver和Chrome搭配使用Selenium和Java

时间:2019-04-05 07:41:37

标签: java selenium google-chrome selenium-webdriver selenium-chromedriver

我正在尝试仅启动chrome驱动程序,但遇到一些超时错误。浏览器确实启动,但几秒钟后关闭,但有以下例外:

系统信息:

Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'MAC-images-MacBook-Pro-1164.local', ip: '----', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_172'
Driver info: driver.version: ChromeDriver] with root cause
at java.util.concurrent.FutureTask.get(FutureTask.java:205)
~[na:1.8.0_172]     at
com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156)
~[guava-25.0-jre.jar:na]    at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:188)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.remote.service.DriverService.start(DriverService.java:179)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:212)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
~[selenium-remote-driver-3.14.0.jar:na]     at
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
~[selenium-chrome-driver-3.14.0.jar:na]     at
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
~[selenium-chrome-driver-3.14.0.jar:na]     at
org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
~[selenium-chrome-driver-3.14.0.jar:na]     at
com.example.tests.bl.impl.AutomationRunner.run(AutomationRunner.java:29)
~[classes/:na]

代码段:

@Component
public class AutomationRunner implements IAutomationRunner {



    @Override
    public void run() throws MalformedURLException {
        System.setProperty("webdriver.chrome.driver",
            "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");

        ChromeDriver driver = new ChromeDriver();
        driver.get("www.google.com");
        driver.close();
        driver.quit();
    }
}

已使用的软件包:

 <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
 </dependency>

有什么想法我想念这里吗?谢谢!

1 个答案:

答案 0 :(得分:0)

此错误消息...

Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'MAC-images-MacBook-Pro-1164.local', ip: '----', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_172'
Driver info: driver.version: ChromeDriver
.
com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156)
~[guava-25.0-jre.jar:na]    at
org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)

...表示 ChromeDriver 无法启动/产生新的 WebBrowser ,即 Chrome浏览器会话。

您的主要问题位于System.setProperty()行中,在该行中您通过了 Google Chrome 二进制文件的绝对路径,而不是 ChromeDriver 二进制。


解决方案

您需要下载用于 Mac OS X 的相关 ChromeDriver 二进制文件,即chromedriver_mac64并将其放置在系统中的任何位置,然后提取 ChromeDriver < / em>二进制文件,并在System.setProperty()内传递绝对路径,如下所示:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");