小编典典

Selenium Webdriver和Chrome驱动程序-无法运行Chrome驱动程序

selenium

我正在尝试运行一个ruby文件,该文件将使用seleniumwebdriver启动chrome驱动程序。我有selenium独立服务器2.35.0。和chromedriver可执行文件已安装。我正在通过运行服务器来启动

java -jar ./selenium-server-standalone-2.35.0.jar -Dwebdriver.chrome.bin=/usr/bin/google-chrome -Dwebdriver.chrome.driver=/home/./chromedriver &

两个会话正在启动,chrome驱动程序无法启动。

05:07:34.328 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=tr
ue, cssSelectorsEnabled=true, browserName=chrome, nativeEvents=false, rotatable=
false, takesScreenshot=false, version=, chrome.switches=[--ignore-certificate-er
rors]}] at URL: /session)
05:07:34.329 INFO - Creating a new session for Capabilities [{platform=ANY, cssS
electorsEnabled=true, javascriptEnabled=true, browserName=chrome, nativeEvents=f
alse, rotatable=false, takesScreenshot=false, chrome.switches=[--ignore-certific
ate-errors], version=}]
Starting ChromeDriver (v2.2) on port 9143
05:07:54.887 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException:
 java.lang.reflect.InvocationTargetException
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
        at java.util.concurrent.FutureTask.get(FutureTask.java:111)
        at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSessi
on.java:176)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSessio
n.java:112)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(Defaul
tSession.java:89)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(De
faultDriverSessions.java:89)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSessio
n.java:63)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConf
ig.java:205)
        at org.openqa.selenium.remote.server.JsonHttpRemoteConfig.handleRequest(
JsonHttpRemoteConfig.java:192)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverS
ervlet.java:201)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.
java:167)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet
.java:139)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.jav
a:428)
        at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler
.java:677)
        at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.j
ava:568)
        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:914)
        at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)

        at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:9
86)
        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:357)
        at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationT
argetException
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructo
r(DefaultDriverFactory.java:72)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(De
faultDriverFactory.java:56)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(
DefaultSession.java:215)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(
DefaultSession.java:1)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession
.java:169)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615)
        at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.callConstructo
r(DefaultDriverFactory.java:62)
        ... 9 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Chrome failed
to start: exited abnormally
  (Driver info: chromedriver=2.2,platform=Linux 3.2.0-38-virtual x86_64) (WARNIN
G: The server did not provide any stacktrace information)
Command duration or timeout: 20.56 seconds
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.
java:191)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHa
ndler.java:145)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:554)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriv
er.java:216)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.jav
a:111)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.jav
a:115)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:150)

        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:129)

        ... 14 more
05:07:54.889 WARN - Exception: unknown error: Chrome failed to start: exited abn
ormally
  (Driver info: chromedriver=2.2,platform=Linux 3.2.0-38-virtual x86_64) (WARNIN
G: The server did not provide any stacktrace information)
Command duration or timeout: 20.56 seconds
Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-virtual',
 java.version: '1.7.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver

An error occurred in an after hook
  NoMethodError: undefined method `quit' for nil:NilClass
  occurred at /home/deploy/deployment/ih2/spec/monitoring_script/NineMonitoring.
rb:24:in `block (2 levels) in <top (required)>'

F

Failures:

  1) MonitoringScript test_script
     Failure/Error: @driver = Selenium::WebDriver.for( :remote, :url => 'http://
localhost:4444/wd/hub', :desired_capabilities => @caps )
     Selenium::WebDriver::Error::UnknownError:
       unknown error: Chrome failed to start: exited abnormally
         (Driver info: chromedriver=2.2,platform=Linux 3.2.0-38-virtual x86_64)
(WARNING: The server did not provide any stacktrace information)
       Command duration or timeout: 20.56 seconds
       Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:
42:01'
       System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-38-vi
rtual', java.version: '1.7.0_25'
       Driver info: org.openqa.selenium.chrome.ChromeDriver (org.openqa.selenium
.WebDriverException)
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):-2:in `newInstance0'
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):57:in `newInstance'
     # [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingC
onstructorAccessorImpl.java):45:in `newInstance'
     # [remote server] java.lang.reflect.Constructor(Constructor.java):526:in `n
ewInstance'
     # [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java
):191:in `createThrowable'
     # [remote server] org.openqa.selenium.remote.ErrorHandler(ErrorHandler.java
):145:in `throwIfResponseFailed'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):554:in `execute'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):216:in `startSession'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):111:in `<init>'
     # [remote server] org.openqa.selenium.remote.RemoteWebDriver(RemoteWebDrive
r.java):115:in `<init>'
     # [remote server] org.openqa.selenium.chrome.ChromeDriver(ChromeDriver.java
):150:in `<init>'
     # [remote server] org.openqa.selenium.chrome.ChromeDriver(ChromeDriver.java
):129:in `<init>'
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):-2:in `newInstance0'
     # [remote server] sun.reflect.NativeConstructorAccessorImpl(NativeConstruct
orAccessorImpl.java):57:in `newInstance'
     # [remote server] sun.reflect.DelegatingConstructorAccessorImpl(DelegatingC
onstructorAccessorImpl.java):45:in `newInstance'
     # [remote server] java.lang.reflect.Constructor(Constructor.java):526:in `n
ewInstance'
     # [remote server] org.openqa.selenium.remote.server.DefaultDriverFactory(De
faultDriverFactory.java):62:in `callConstructor'
     # [remote server] org.openqa.selenium.remote.server.DefaultDriverFactory(De
faultDriverFactory.java):56:in `newInstance'
     # [remote server] org.openqa.selenium.remote.server.DefaultSession$BrowserC
reator(DefaultSession.java):215:in `call'
     # [remote server] org.openqa.selenium.remote.server.DefaultSession$BrowserC
reator(DefaultSession.java):1:in `call'
     # [remote server] java.util.concurrent.FutureTask$Sync(FutureTask.java):334
:in `innerRun'
     # [remote server] java.util.concurrent.FutureTask(FutureTask.java):166:in `
run'
     # [remote server] org.openqa.selenium.remote.server.DefaultSession$1(Defaul
tSession.java):169:in `run'
     # [remote server] java.util.concurrent.ThreadPoolExecutor(ThreadPoolExecuto
r.java):1145:in `runWorker'
     # [remote server] java.util.concurrent.ThreadPoolExecutor$Worker(ThreadPool
Executor.java):615:in `run'
     # [remote server] java.lang.Thread(Thread.java):724:in `run'
     # ./NineMonitoring.rb:11:in `block (2 levels) in <top (required)>'

Finished in 20.75 seconds
1 example, 1 failure

Failed examples:

rspec ./filename.rb:28 # filename test_script

这是在我使用以下文件运行文件之后

bundle exec rspec filename.rb

我对此并不陌生,无法找出问题所在。而且,我也试图让它无头运行,所以我正在运行Xvfb。有人可以帮我指出我所犯的错误并启动chromedriver吗?

更新:

根据建议,我已经更新了ChromeDriver并收到以下错误:

10:19:44.378 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=tr
ue, cssSelectorsEnabled=true, browserName=chrome, nativeEvents=false, rotatable=
false, takesScreenshot=false, version=, chrome.switches=[--ignore-certificate-er
rors]}] at URL: /session)
10:19:44.417 INFO - Creating a new session for Capabilities [{platform=ANY, cssS
electorsEnabled=true, javascriptEnabled=true, browserName=chrome, nativeEvents=f
alse, rotatable=false, takesScreenshot=false, chrome.switches=[--ignore-certific
ate-errors], version=}]
Starting ChromeDriver (v2.9.248304) on port 21908
[0.723][WARNING]: PAC support disabled because there is no system implementation

An error occurred in an after hook
  NoMethodError: undefined method `quit' for nil:NilClass
  occurred at /home/deploy/deployment/ih2/spec/monitoring_script/NineMonitoring.
rb:24:in `block (2 levels) in <top (required)>'

While running the file:

Failures:

  1) MonitoringScript test_script
     Failure/Error: @driver = Selenium::WebDriver.for( :remote, :url => 'http://
localhost:4444/wd/hub', :desired_capabilities => @caps )
     Timeout::Error:
       Timeout::Error
     # ./testfile.rb:11:in `block (2 levels) in <top (required)>'

Finished in 1 minute 0.19031 seconds
1 example, 1 failure

谁能帮我找出问题所在吗?


阅读 318

收藏
2020-06-26

共1个答案

小编典典

使用Java 1.6可以达到目的。

在尝试Selenium-server-standalone-2.37.0.jar之后;谷歌浏览器33.0.1750.117;
chromedriver_linux64_2.2; Java版本“ 1.7”,发现Java版本与其他版本不兼容。从而解决了我的问题。

2020-06-26