简体   繁体   中英

open a new tab in RSelenium

How do you open a new tab in RSelenium ? Specifically, how do you specify the control key to send "CTRL + T" to the window? I attempt:

require(RSelenium)
RSelenium::startServer()
dr = remoteDriver()
dr$open()
b = remDr$findElement(using = 'tag', value = "body")
b$sendKeysToElement(list("CONTROL + T")) #this does not work

RSelenium has a list of keyboard keys see ?selKeys

You can open a new tab on a link as follows:

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 doesnt support tabs however see for example https://code.google.com/p/selenium/issues/detail?id=5572 so it is better to open in a new window

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}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM