问题
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"))
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.
回答1:
It's not in documentation, but I tried to press control again, and another press released the keypress.
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()
Strange it's not in the documentation though.
Documentation for sendKeysToActiveElement(sendKeys)
:
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.
来源:https://stackoverflow.com/questions/49703145/how-to-release-a-keypress-in-rselenium