remDr$open()在使用RSelenium和Docker时挂起

hsvhsicv  于 2023-05-28  发布在  Docker
关注(0)|答案(1)|浏览(99)

在R中有以下代码:

library(RSelenium)
shell('docker run -d -p 4446:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4446L, browserName = "firefox")
remDr$open()
remDr$navigate("http://www.google.com/ncr")
remDr$getTitle()

当运行它时,它在以下阶段冻结,什么也没有发生:

> remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4446L, browserName = "firefox")
> remDr$open()
[1] "Connecting to remote server"

我怀疑这可能是因为我通常使用Chrome作为我的浏览器,但即使我将浏览器名称更改为Chrome,如下所示,同样的问题:

remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4446L, browserName = "chrome")

然后我还尝试了以下操作:

driver <- rsDriver(port = 4446L, browser = "chrome", chromever = NULL)

这得到以下结果:

checking Selenium Server versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking geckodriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking phantomjs versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
[1] "Connecting to remote server"

Selenium message:Unable to create new service: ChromeDriverService
Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10'
System info: host: 'DESKTOP-HKH3SN0', ip: '10.0.0.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_371'
Driver info: driver.version: unknown

Could not open chrome browser.
Client error message:
     Summary: SessionNotCreatedException
     Detail: A new session could not be created.
     Further Details: run errorDetails method
Check server log for further details.

检查日志详细信息:

$stderr
 [1] "13:03:54.084 INFO [GridLauncherV3.parse] - Selenium server version: 4.0.0-alpha-2, revision: f148142cf8"                                                                                              
 [2] "13:03:54.218 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4446"                                                                                     
 [3] "13:03:54.606 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet"                                                                                                                          
 [4] "13:03:55.183 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4446"                                                                                                             
 [5] "13:03:56.274 INFO [ActiveSessionFactory.apply] - Capabilities are: {"                                                                                                                                 
 [6] "  \"browserName\": \"chrome\","                                                                                                                                                                       
 [7] "  \"javascriptEnabled\": true,"                                                                                                                                                                       
 [8] "  \"nativeEvents\": true,"                                                                                                                                                                            
 [9] "  \"version\": \"\""                                                                                                                                                                                  
[10] "}"                                                                                                                                                                                                    
[11] "13:03:56.275 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)"

$stdout
character(0)
qni6mghb

qni6mghb1#

我现在也遇到了同样的问题,正在寻找新的想法。在RSelenium github中有一个讨论这个问题的主题(https://github.com/ropensci/RSelenium/issues/275)。我还没有能够解决这个问题,加载最新的wdman版本提到作为一个可能的修复。然而,作为测试的一部分,我并行运行了一个旧版本,没有任何问题,并发现移动到一个旧的 selenium chrome 图像(例如,4.2.2)固定开挂
所以在新的服务器上我拉了4.2.2的图像

docker pull selenium/standalone-chrome:4.2.2

并在docker命令中显式调用它

docker run -d -p 4445:4444 --shm-size 4g selenium/standalone-chrome:4.2.2

从那里我可以构造并打开远程驱动程序对象

相关问题