如何在RSelenium
中打开新标签?具体来说,如何指定控制键以发送" CTRL + T"到窗口?我尝试了:
require(RSelenium)
RSelenium::startServer()
dr = remoteDriver()
dr$open()
b = remDr$findElement(using = 'tag', value = "body")
b$sendKeysToElement(list("CONTROL + T")) #this does not work
答案 0 :(得分:5)
RSelenium有一个键盘键列表,请参阅?selKeys
您可以按如下方式在链接上打开新标签页:
library(RSelenium)
RSelenium::startServer()
dr <- remoteDriver()
dr$open()
dr$navigate("http://www.stackoverflow.com")
# find the Users tab
webElem <- dr$findElement("id", "nav-users")
dr$mouseMoveToLocation(webElement = webElem) # move to the required element
dr$click(2) # right mouse button click
webElem$sendKeysToElement(list(key = "control", "t")) # open a new tab by sending ctrl+t
Selenium不支持标签,但请参见https://code.google.com/p/selenium/issues/detail?id=5572,因此最好在新窗口中打开
webElem$sendKeysToElement(list(key = "control", "w"))
> dr$getWindowHandles()
[[1]]
[1] "{64da9f4a-4974-4e11-a078-35785ac31227}"
[2] "{952d4b9c-9955-4233-a048-d2e9b043117c}"
> dr$getCurrentWindowHandle()
[[1]]
[1] "{64da9f4a-4974-4e11-a078-35785ac31227}"
> dr$switchToWindow("{952d4b9c-9955-4233-a048-d2e9b043117c}")
> dr$getCurrentWindowHandle()
[[1]]
[1] "{952d4b9c-9955-4233-a048-d2e9b043117c}"