如何在 Rselenium 中释放按键 [英] How to release a keypress in Rselenium

查看:23
本文介绍了如何在 Rselenium 中释放按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试成功按下控制键:

I tried to press control key successfully with:

rD <- rsDriver (browser = 'chrome',chromever = "latest",port = 4445L)
chrome_client <-rD$client
chrome_client$sendKeysToActiveElement(list(key = "control"))

但问题是我不能释放这个键,所以如果我点击另一个链接它会创建一个新标签.
我在 google 和 stackoverflow 上搜索过,但还没有找到 Rselenium 的解决方案.

But the problem is that I can't release this key, so it creates a new tab if I click another link.
I searched on google and stackoverflow, but found no solutions for Rselenium yet.

推荐答案

文档中没有,但我再次尝试按下控制,再次按下释放了按键.

It's not in documentation, but I tried to press control again, and another press released the keypress.

示例:
无需按两次,将打开一个新选项卡.但是使用 sendKeysToActiveElement() 按下控制键两次释放按键,它不会创建一个新选项卡.

example:
Without pressing it twice, a new tab will be opened. But press control twice with sendKeysToActiveElement() release the keypress and it won't create a new tab.

rD <- rsDriver (browser = 'chrome',chromever = "latest",port = 4445L)
chrome_client <-rD$client
chrome_client$navigate("https://www.google.com/")
chrome_client$sendKeysToActiveElement(list(key = "control"))
ele_gmail <- chrome_client$findElement(using = "partial",value = "Gmail")
chrome_client$sendKeysToActiveElement(list(key = "control")) #press the same key again to release the keypress
ele_gmail$clickElement()

奇怪的是它不在文档中.
sendKeysToActiveElement(sendKeys) 的文档:

Strange it's not in the documentation though.
Documentation for sendKeysToActiveElement(sendKeys):

向活动元素发送一系列击键.除了隐式终止之外,此命令在各个方面都类似于 send keys 命令:在调用结束时不会释放修饰符.相反,修改键的状态在调用之间保持不变,因此可以在按下修改键的同时执行鼠标交互.击键作为列表发送.纯文本作为列表的未命名元素输入.键盘条目在 'selKeys' 中定义,应以名称 'key' 列出.查看示例.

Send a sequence of key strokes to the active element. This command is similar to the send keys command in every aspect except the implicit termination: The modifiers are not released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed. The key strokes are sent as a list. Plain text is enter as an unnamed element of the list. Keyboard entries are defined in 'selKeys' and should be listed with name 'key'. See the examples.

这篇关于如何在 Rselenium 中释放按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆