Selenium Webdriver

JAVA开发 workingTime 1484℃ 0评论

遇到的问题

The path to the driver executable must be set by the webdriver.gecko.driver system property


Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:33)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:139)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at org.selenium.test.Test_01.main(Test_01.java:25)

原因:没有找到chrome驱动程序,意思就是没有配置浏览器。
解决:加入如下代码,指定浏览器程序(我的是mac电脑,所以加入的是mac下的地址)


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

Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException


Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:192)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at org.selenium.test.Test_01.main(Test_01.java:26)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:21792/status] to be available after 20004 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
    ... 9 more
Caused by: java.util.concurrent.TimeoutException
    at java.util.concurrent.FutureTask.get(FutureTask.java:205)
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:148)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
    ... 10 more

原因:还是驱动问题
解决:从报错可以看出chromedriver无法调用,因为我笔记本上装有chrome浏览器,所以一开始我以为在配置测试的浏览器时System.setProperty()中填入的就是我笔记本上chrome的安装位置,即/Applications/Google Chrome.app/Contents/MacOS/Google Chrome,经查阅得知selenium操作chrome浏览器是通过chromedriver这样一个东西,所以还必须下载对应的浏览器driver,所以需要下载chrome驱动,下载chromedriver的网址,在LATEST_RELEASE文件中是最新驱动程序的版本号

之后修改System.setProperty()中的驱动地址即可。

转载请注明:R&M » Selenium Webdriver

喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

备案号:京ICP备14044161号;联系我:rm@rmworking.com