gpt4 book ai didi

r - 在 RSelenium 中打开一个新选项卡

转载 作者:行者123 更新时间:2023-12-04 02:04:56 24 4
gpt4 key购买 nike

如何在 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

最佳答案

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

关于r - 在 RSelenium 中打开一个新选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26559192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com