r - RSelenium RemoteDriver 未连接到端口 4445L
问题描述
我一直在关注 Docker/RSelenium 教程:https ://docs.ropensci.org/RSelenium/articles/docker.html
我已经成功地托管了我自己的 Selenium 服务器:
# sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0c673ba37477 selenium/standalone-chrome:88.0 "/opt/bin/entry_poin…" 3 minutes ago Up 3 minutes 5900/tcp, 0.0.0.0:4445->4444/tcp zealous_shannon
当我按照教程运行以下命令时:
library(RSelenium)
remDr <- remoteDriver(port = 4445L)
remDr$open()
我得到以下输出,没有错误消息:
[1] "Connecting to remote server"
$id
[1] NA
预期的输出是:
## [1] "Connecting to remote server"
## $applicationCacheEnabled
## [1] TRUE
##
## $rotatable
## [1] FALSE
##
## $handlesAlerts
## [1] TRUE
##
## $databaseEnabled
## [1] TRUE
##
## $version
## [1] "45.0.2"
##
## $platform
## [1] "LINUX"
##
## $nativeEvents
## [1] FALSE
##
## $acceptSslCerts
## [1] TRUE
##
## $webdriver.remote.sessionid
## [1] "644c353a-34b8-4bb4-bcff-746df5a30af8"
##
## $webStorageEnabled
## [1] TRUE
##
## $locationContextEnabled
## [1] TRUE
##
## $browserName
## [1] "firefox"
##
## $takesScreenshot
## [1] TRUE
##
## $javascriptEnabled
## [1] TRUE
##
## $cssSelectorsEnabled
## [1] TRUE
##
## $id
## [1] "644c353a-34b8-4bb4-bcff-746df5a30af8"
这使我无法继续学习本教程。知道为什么我通过 RemoteDriver 的连接不能正常工作吗?
解决方案
为您使用的操作系统和浏览器正确设置连接参数。如果图像基于chrome
浏览器并且驱动程序的默认配置是firefox
.
要更改此设置,您需要添加browserName = "chrome"
. 为了清楚起见,我建议始终添加服务器的 IP 地址,因此,添加remoteServerAddr = <<server IP>>
找出驱动程序的默认参数的方法是检查实例化的远程驱动程序,remDr
它将向您显示驱动程序的默认配置是什么。
>remDr
$remoteServerAddr
[1] "localhost"
$port
[1] 4445
$browserName
[1] "firefox"
$version
[1] ""
$platform
[1] "ANY"
$javascript
[1] TRUE
$nativeEvents
[1] TRUE
$extraCapabilities
list()
所以在设置正确的参数后,我能够连接到暴露端口上的 RSelenum。
library(RSelenium)
> remDr <- remoteDriver(
+ remoteServerAddr = "localhost",
+ port = 4445L,
+ browserName = "chrome")
> remDr$open()
[1] "Connecting to remote server"
$acceptInsecureCerts
[1] FALSE
$browserName
[1] "chrome"
$browserVersion
[1] "88.0.4324.150"
$chrome
$chrome$chromedriverVersion
[1] "88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784})"
$chrome$userDataDir
[1] "/tmp/.com.google.Chrome.egZzL9"
$`goog:chromeOptions`
$`goog:chromeOptions`$debuggerAddress
[1] "localhost:36841"
$networkConnectionEnabled
[1] FALSE
$pageLoadStrategy
[1] "normal"
$platformName
[1] "linux"
$proxy
named list()
$`se:options`
$`se:options`$cdp
[1] "http://172.17.0.2:4444/session/eaed604c5fae33476755e4ba3e1c1d9e/se/cdp"
$setWindowRect
[1] TRUE
$strictFileInteractability
[1] FALSE
$timeouts
$timeouts$implicit
[1] 0
$timeouts$pageLoad
[1] 300000
$timeouts$script
[1] 30000
$unhandledPromptBehavior
[1] "dismiss and notify"
$`webauthn:extension:largeBlob`
[1] TRUE
$`webauthn:virtualAuthenticators`
[1] TRUE
$id
[1] "eaed604c5fae33476755e4ba3e1c1d9e"
推荐阅读
- pandas - 使用 groupby 添加标志列顶部/底部 N 值
- flutter - 为什么当我在其小部件中调用 Flutter 有状态小部件时,它没有改变另一个有状态小部件的状态
- java - 如何使用 Maven 插件制作包含资源的可执行 jar
- excel - Excel - 获取最后一场比赛
- python - 在 Python 中使用多处理填充多个列表
- java - 使用 spring-boot 将多维数据集插入 postgres 数据库
- qt - 在 microsoft visual studio 2019 中生成 moc 文件
- vba - 如何根据特定单元格上的值在 Excel 中触发 VBA 宏?
- design-patterns - 使用字符串与枚举作为工厂方法的参数?
- reactjs - Flow Cadence 未能在执行节点上执行脚本:rpc error: code = DeadlineExceeded desc = context deadline exceeded