我正在尝试使用带有幻像的RSelenium登录网站mol.medicover.pl。 我无法使用sendKeysToElement命令发送登录和传递 我认为这个问题是迫使幻影接受sslcerts。 我的代码:
library(RSelenium)
my_extra <- list("--ignore-ssl-errors=true", "--ssl-protocol=tlsv1", "--web-security=no")
cDrv3 <- RSelenium::rsDriver(port = 4569L, browser = "phantomjs",
extraCapabilities = my_extra)
remDr <- cDrv3[["client"]]
remDr$navigate("https://mol.medicover.pl")
log_into <- remDr$findElement(using = "xpath", "//*[@id=\"oidc-submit\"]")
log_into$clickElement()
windows_list <- remDr$getWindowHandles()
remDr$closeWindow()
remDr$switchToWindow(windows_list[[2]])
card_number <- remDr$findElement(using = "xpath", "//*[@id=\"username-email\"]")
card_number$sendKeysToElement(list("test", key = "enter"))
在最后一个代码行之后,我收到错误:
Selenium message:TypeError - undefined is not a function
(evaluating _getTagName(currWindow).toLowerCase()')
Command duration or timeout: 9 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'kacper-Lenovo-ideapad-Y700-15ISK', ip: '127.0.1.1',
os.name: 'Linux', os.arch: 'amd64',os.version: '4.8.0-58
generic',java.version: '1.8.0_131'
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false,
handlesAlerts=false, databaseEnabled=false, version=2.1.1, platform=LINUX,
browserConnectionEnabled=false, proxy=Proxy(direct), nativeEvents=true,
acceptSslCerts=false, driverVersion=1.2.0, locationContextEnabled=false,
webStorageEnabled=false, browserName=phantomjs, takesScreenshot=true,
driverName=ghostdriver, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: c0a7edf0-6fc9-11e7-ba6e-a34a400bb453
Error: Summary: UnknownCommand
Detail: The requested resource could not be found, or a request was
received using an HTTP method that is not supported by the mapped resource.
class: org.openqa.selenium.UnsupportedCommandException
Further Details: run errorDetails method
我尝试使用wdman包来启动Rselenium,但我堆叠了同样的问题
cDrv <- phantomjs(extras = "--ignore-ssl-errors=true --ssl-protocol=any
--web-security=no", port =4565L, version = "1.9.8")
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4565,
browserName = "phantomjs")
remDr$open()
我一直在开始我的会话,我得到$ acceptSslCerts = FALSE。我不知道如何强制phantomjs改变它。
[1] "Connecting to remote server"
$browserName
[1] "phantomjs"
$version
[1] "2.1.1"
$driverName
[1] "ghostdriver"
$driverVersion
[1] "1.2.0"
$platform
[1] "linux-unknown-64bit"
$javascriptEnabled
[1] TRUE
$takesScreenshot
[1] TRUE
$handlesAlerts
[1] FALSE
$databaseEnabled
[1] FALSE
$locationContextEnabled
[1] FALSE
$applicationCacheEnabled
[1] FALSE
$browserConnectionEnabled
[1] FALSE
$cssSelectorsEnabled
[1] TRUE
$webStorageEnabled
[1] FALSE
$rotatable
[1] FALSE
$acceptSslCerts
[1] FALSE
$nativeEvents
[1] TRUE
$proxy
proxy$proxyType
[1] "direct"
$id
[1] "8166b460-6fcd-11e7-bac0-1f0af3c89c32"
答案 0 :(得分:3)
这是一个已知问题,请参阅https://github.com/ariya/phantomjs/issues/14211
作为一种解决方法,您可以使用更高版本的ghostdriver然后与phantomjs一起打包。转到https://github.com/detro/ghostdriver/releases 我下载了ghostdriver 2.1.0版。您可以参考此路径 更新了ghostdriver作为extraCapability:
library(RSelenium)
my_extra <- list(phantomjs.ghostdriver.path = "/home/john/ghostdriver-2.1.0/src/main.js")
cDrv3 <- RSelenium::rsDriver(port = 4569L, browser = "phantomjs",
extraCapabilities = my_extra)
remDr <- cDrv3[["client"]]
remDr$navigate("https://mol.medicover.pl")
log_into <- remDr$findElement(using = "xpath", "//*[@id=\"oidc-submit\"]")
log_into$clickElement()
windows_list <- remDr$getWindowHandles()
remDr$closeWindow()
remDr$switchToWindow(windows_list[[2]])
card_number <- remDr$findElement(using = "xpath", "//*[@id=\"username-email\"]")
card_number$sendKeysToElement(list("test", key = "enter"))
card_number$screenshot(display = TRUE)
#clean up
remDr$close()
cDrv3$server$stop()