Rselenuim/Docker - 无法连接到 firefox 的远程服务器

问题描述 投票:0回答:1

我的铷突然停止了。我寻找答案,尝试了所有这些,但没有任何运气。然后我卸载了 docker 并重新安装,重新启动了我的机器等等。终于设法让一段代码工作了,所以我知道我的机器没有坏。

对我有用的代码是:

library(RSelenium)

# Specify the port
port <- as.integer(4444L + rpois(lambda = 1000, 1))

# opens a new browser
cDrv3<- rsDriver(port = port,browser = "firefox",chromever = NULL, )

remDr <- cDrv3[["client"]]

remDr$navigate("https://www.google.com")
remDr$getTitle()
remDr$closeWindow()

但是这段代码太麻烦了,每次都要下载浏览器并打开一个新的浏览器。这使得它缓慢且低效。

我想要的是让这段代码工作:

system("docker run -d -p 4445:4444 selenium/standalone-firefox:latest") # this part works.
remDr <<- remoteDriver(remoteServerAddr = "localhost",  browserName = "firefox", port = 4445)
remDr$open(silent = FALSE)

当前,当我运行

remDr$open(silent = FALSE)
时,我收到以下错误:

remDr$open(silent = FALSE)
[1] "Connecting to remote server"
Error in checkError(res) : 
  Undefined error in httr call. httr output: Failed to connect to localhost port 5411 after 2260 ms: Couldn't connect to server

我已经尝试了所有的建议

Postgres Docker - 无法从远程服务器连接

无法执行rsDriver(连接被拒绝)

R Rselenium“...无法连接到本地主机端口 4444:连接被拒绝”

RSelenium 在创建服务器时不工作

有什么新想法可以解决我的问题吗?

提前致谢。

r rselenium docker-selenium
1个回答
0
投票

RSelenium 不适用于最新版本的 Selenium。要么:

  1. 使用旧版本的 Selenium(例如
    docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-firefox:4.8.3
    )。您可能需要尝试找到 RSelenium 兼容的版本。
  2. 使用较新的 selenium 包,可与最新版本的 Selenium 配合使用。
© www.soinside.com 2019 - 2024. All rights reserved.