必须通过webdriver.chrome.driver系统属性(php)设置驱动程序可执行文件的路径

时间:2016-09-16 07:07:18

标签: php selenium

我在运行php selenium测试时遇到问题。我刚刚切换到Ubuntu操作系统,现在我在selenium服务器上获得了这个异常堆栈恍惚。

Selenium服务器

 08:58:49.965 INFO - Launching a standalone Selenium Server
    08:58:49.986 INFO - Java: Oracle Corporation 25.101-b13
    08:58:49.986 INFO - OS: Linux 4.4.0-36-generic amd64
    08:58:49.996 INFO - v2.53.0, with Core v2.53.0. Built from revision 35ae25b
    08:58:50.040 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
    registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform LINUX
    08:58:50.041 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
    registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform LINUX
    08:58:50.041 INFO - Driver class not found: com.opera.core.systems.OperaDriver
    08:58:50.041 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
    08:58:50.041 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
    registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform LINUX
    08:58:50.042 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
    08:58:50.042 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
    08:58:50.075 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
    08:58:50.075 INFO - Selenium Server is up and running
    08:59:41.556 INFO - Executing: [new session: Capabilities [{browserName=chrome, platform=LINUX}]])
    08:59:41.566 INFO - Creating a new session for Capabilities [{browserName=chrome, platform=LINUX}]
    08:59:41.573 WARN - Exception thrown
    java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
    System info: host: 'Keson', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-36-generic', java.version: '1.8.0_101'
    Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:124)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
        at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:79)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:204)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:166)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:132)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
        at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
        at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
        at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
        at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
        at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
        at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
        at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
        at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
        at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
        at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
        at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
    Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
    Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
    System info: host: 'Keson', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-36-generic', java.version: '1.8.0_101'
    Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:113)
        at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:103)
        ... 9 more
    Caused by: 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:199)
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
        at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:138)
        ... 14 more
    08:59:41.576 WARN - Exception: 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

Chromdriver正在运行

Starting ChromeDriver (v2.9.248304) on port 9515

当我运行测试时,这是一个错误

There was 1 error:
UnknownServerException: 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

为什么这个问题出现了?怎么解决?如果您需要任何其他信息,请告诉我,我会提供。 提前谢谢

1 个答案:

答案 0 :(得分:6)

您应该像这样设置chrome驱动程序选项:

java -jar selenium-server-standalone-2.53.0.jar -Dwebdriver.chrome.driver=chromedriver.exe

-Dwebdriver.chrome.driver=之后你应该把路径放到cromedriver上。