简体   繁体   English

在RSelenium中打开一个新标签

[英]open a new tab in RSelenium

How do you open a new tab in RSelenium ? 如何在RSelenium打开一个新选项卡? Specifically, how do you specify the control key to send "CTRL + T" to the window? 具体来说,如何指定控制键以将“ CTRL + T”发送到窗口? 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 RSelenium有键盘键的列表,请参见?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 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}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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