ropensci / RSelenium

An R client for Selenium Remote WebDriver
https://docs.ropensci.org/RSelenium
343 stars 81 forks source link

Does RSelenium handle hotkeys? #287

Open Camilo-Mora opened 9 months ago

Camilo-Mora commented 9 months ago

I was not able to find a solution on the web about this. So I am trying here.

The question is, can RSelenium handle hotkeys? I noted that only the control + a hot key works... but all others do not.

Hotkeys is a practical solution to activate extensions, or run operations outside DOM, which are complicated to handle with Selenium...

Below I show some examples of hotkeys that should operate in any chrome browser. I put them as examples of shortcuts that work when entered manually but not when using Rselenium... they are just as reference for the problem. My particular need is to activate a Extension that uses Control+Shift+S as shortcut.

library(RSelenium)
rD <- rsDriver(browser = "firefox") 

remDr <- rD$client
remDr$navigate("https://www.google.com")

remDr$navigate("https://www.amazon.com")

#use hot key to see history of visiting the two pages above.
elem <- remDr$findElement("xpath", "//body")
elem$sendKeysToElement(list(key = 'control',  'H'))

#here is another example with three keys. This one should reload the page
#the reload shortcut control+shift+R
elem$sendKeysToElement(list(key = 'control',  key = 'shift','R'))

#it is very intriguing that the select all shortcut, control + a, works well.
webElem$sendKeysToElement(list(key = "control", "a"))