这是可复制的示例(受https://ropensci.org/tutorials/rselenium_tutorial/启发):
library("RSelenium")
remDr <- remoteDriver(remoteServerAddr = "localhost"
, port = 4444
, browserName = "firefox"
)
rDrD <- rsDriver(port = 4550L, browser = "firefox", version = "latest", geckover = "latest", iedrver = NULL, phantomver = "2.1.1",
verbose = TRUE, check = TRUE)
remDr <- rDrD$client
remDr$navigate("http://www.google.com/ncr")
webElem <- remDr$findElement(using = "xpath", "/html/body/div/div[3]/form/div[2]/div/div[1]/div/div[1]/input")
webElem$sendKeysToElement(list("R Cran", key = "enter"))
webElems <- remDr$findElements(using = 'class', "LC20lb")
resHeaders <- unlist(lapply(webElems, function(x){x$getElementText()}))
webElem <- webElems[[which(resHeaders == "The Comprehensive R Archive Network")[1]]]
remDr$mouseMoveToLocation(webElement = webElem)
remDr$click(2)
我尝试过click(1),click(0):都具有相同的结果,即左键点击的预期结果。
这不是特定网站的人工产物。
注意,我也没有设法发送Ctrl + W(打开一个新窗口)。
我使用的是Windows,大多数最近使用的Rselenium和Firefox(R 3.6.0),但是在更新R和Rselenium之前,我观察到了相同的行为。