如何使用ChromeDriver和RSelenium从R控制台启动chrome?

时间:2017-01-24 18:49:46

标签: r selenium-webdriver webdriver selenium-chromedriver rselenium

我正在尝试使用命令

从R控制台打开chrome
> remDr <- remoteDriver(remoteServerAddr = "localhost" , port = 4444 , browserName = "chrome")
> remDr$open()

这些版本都是最新的。 铬 - 55 chromedriver - 2.27 selenium独立服务器 - 3.0.1

我可以使用以下错误消息连接到远程服务器,但它无法打开浏览器。

$message
[1] "unknown error: Chrome failed to start: exited abnormally\n  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64)"

但是当我尝试导航时,它会抛出以下错误,

> remDr <- remoteDriver(remoteServerAddr = "localhost" , port = 4444 , browserName = "chrome")

> remDr$open()
[1] "Connecting to remote server"
$webdriver.remote.sessionid
[1] "17e6e349-9a67-4423-a817-1798a3e60933"

$locationContextEnabled
[1] TRUE

$webStorageEnabled
[1] TRUE

$takesScreenshot
[1] TRUE

$javascriptEnabled
[1] TRUE

$message
[1] "unknown error: Chrome failed to start: exited abnormally\n  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64)"

$hasTouchScreen
[1] TRUE

$platform
[1] "ANY"

$cssSelectorsEnabled
[1] TRUE

$id
[1] "17e6e349-9a67-4423-a817-1798a3e60933"


> remDr$navigate(url)

Selenium message:no such session
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 38 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'akshay-300E4Z-300E5Z-300E7Z', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-64-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64), platform=ANY}]
Session ID: 31de4b0c481e4d0f4fae80ad2920f5c3

Error:   Summary: NoSuchDriver
     Detail: A session is either terminated or not started
     class: org.openqa.selenium.NoSuchSessionException
     Further Details: run errorDetails method

服务器启动时的selenium服务器日志: -

$ java -jar -Dwebdriver.chrome.driver=/home/hdpusr/ChromeDriver/chromedriver selenium-server-standalone-3.0.1.jar
19:24:09.727 INFO - Selenium build info: version: '3.0.1', revision: '1969d75'
19:24:09.728 INFO - Launching a standalone Selenium Server
2017-01-24 19:24:09.747:INFO::main: Logging initialized @299ms
19:24:09.808 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
19:24:09.808 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
19:24:09.809 INFO - Driver class not found: com.opera.core.systems.OperaDriver
19:24:09.809 INFO - Driver provider com.opera.core.systems.OperaDriver registration is skipped:
Unable to create new instances on this machine.
19:24:09.809 INFO - Driver class not found: com.opera.core.systems.OperaDriver
19:24:09.809 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
19:24:09.810 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
2017-01-24 19:24:09.853:INFO:osjs.Server:main: jetty-9.2.15.v20160210
2017-01-24 19:24:09.882:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@6d8a00e3{/,null,AVAILABLE}
2017-01-24 19:24:09.900:INFO:osjs.ServerConnector:main: Started ServerConnector@4f933fd1{HTTP/1.1}{0.0.0.0:4444}
2017-01-24 19:24:09.900:INFO:osjs.Server:main: Started @452ms
19:24:09.900 INFO - Selenium Server is up and running

以下是运行时的selenium服务器日志

remDr$open()

服务器日志: -

19:24:28.515 INFO - SessionCleaner initialized with insideBrowserTimeout 0 and clientGoneTimeout 1800000 polling every 180000
19:24:28.548 INFO - Executing: [new session: Capabilities [{nativeEvents=true, browserName=chrome, javascriptEnabled=true, version=, platform=ANY}]])
19:24:28.566 INFO - Creating a new session for Capabilities [{nativeEvents=true, browserName=chrome, javascriptEnabled=true, version=, platform=ANY}]
Starting ChromeDriver 2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320) on port 20845
Only local connections are allowed.
19:24:28.990 INFO - Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
19:25:29.106 INFO - Detected dialect: OSS
19:25:29.154 INFO - Done: [new session: Capabilities [{nativeEvents=true, browserName=chrome, javascriptEnabled=true, version=, platform=ANY}]]

以下是运行时的selenium服务器日志

remDr$navigate(url)

服务器日志: -

20:33:42.918 INFO - Executing: [get: https://www.goodreads.com/book/show/18619684-the-time-traveler-s-wife#other_reviews])
No protocol specified
20:33:42.961 WARN - Exception thrown
org.openqa.selenium.NoSuchSessionException: no such session
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'akshay-300E4Z-300E5Z-300E7Z', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-64-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64), platform=ANY}]
Session ID: e19869d41d81d1bbc51432cf08bec577
    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.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:322)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.openqa.selenium.support.events.EventFiringWebDriver$2.invoke(EventFiringWebDriver.java:103)
    at com.sun.proxy.$Proxy4.get(Unknown Source)
    at org.openqa.selenium.support.events.EventFiringWebDriver.get(EventFiringWebDriver.java:162)
    at org.openqa.selenium.remote.server.handler.ChangeUrl.call(ChangeUrl.java:40)
    at org.openqa.selenium.remote.server.handler.ChangeUrl.call(ChangeUrl.java:25)
    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)
20:33:42.967 WARN - Exception: no such session
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 16 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'akshay-300E4Z-300E5Z-300E7Z', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-64-generic', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64), platform=ANY}]
Session ID: e19869d41d81d1bbc51432cf08bec577

我也尝试使用 rsDriver 运行selenium服务器,但没有任何区别,以下是 rsDriver 结果

> rD <- rsDriver(port = 4567L, browser = c("chrome", "firefox", "phantomjs", "internet explorer"), version = "latest", chromever = "latest", geckover = "latest", iedrver = NULL, phantomver = NULL, verbose = TRUE, check = TRUE)
checking Selenium Server versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking geckodriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
[1] "Connecting to remote server"
$webdriver.remote.sessionid
[1] "83941a25-4d50-426f-a006-2f056462f2b0"
$locationContextEnabled
[1] TRUE
$webStorageEnabled
[1] TRUE
$takesScreenshot
[1] TRUE
$javascriptEnabled
[1] TRUE
$message
[1] "unknown error: Chrome failed to start: exited abnormally\n  (Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.19.0-64-generic x86_64)"
$hasTouchScreen
[1] TRUE
$platform
[1] "ANY"
$cssSelectorsEnabled
[1] TRUE
$id
[1] "83941a25-4d50-426f-a006-2f056462f2b0"

请有人在这里帮助我。 感谢

1 个答案:

答案 0 :(得分:1)

chrome / chromedriver / selenium服务器似乎存在问题。您需要详细记录以更详细地检查:

library(wdman)
library(RSelenium)
selServ <- selenium(jvmargs = c("-Dwebdriver.chrome.verboseLogging=true"))
remDr <- remoteDriver(port = 4567L, browserName = "chrome")
remDr$open()
selServ$log()

或者如果您更喜欢在终端中单独运行,请启动selenium服务器,如下所示:

java -Dwebdriver.chrome.verboseLogging=true -Dwebdriver.chrome.driver=/home/hdpusr/ChromeDriver/chromedr‌​‌​iver -jar selenium-server-standalone-3.0.1.jar -port 4444

如果问题不明显,您可以向https://bugs.chromium.org/p/chromedriver/issues/list提交问题。