4

I would like to send two simultaneous keys such as ALT+S to the sendKeysToActiveElement( function of the R Selenium webdriver. I only see implementations in Java and C. Can this be done?

Kim
  • 4,080
  • 2
  • 30
  • 51
user5822712
  • 53
  • 1
  • 7

3 Answers3

4

If you want to send a single keystroke then use:

cl$sendKeysToActiveElement(sendKeys = list(key = "tab"))

If you press more than two keystrokes then use:

cl$sendKeysToActiveElement(sendKeys = list(key = "alt", key = "S"))
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
2

There are 2 ways to send key presses in the in the R version of Selenium. The first way, as mentioned, is by sending the desired button in the key argument. The second way is by sending the raw UTF-8 character codes without the key argument. Generally, this is undesired because it's difficult to remember all the codes, but when wanting to input simultaneous key presses, it's the only way I've found to make it work since the list option does appear to send inputs sequentially.

In this scenario, the UTF 8 code for alt is \uE00a

and the UTF 8 code for s is \u0073

We can combine these into a single value, like so:

remDr$sendKeysToActiveElement(sendKeys = list("\uE00a\u0073"))

I'm unfamiliar with the alt + s shortcut, but this does work with something like shift + tab to navigate through different elements in reverse on a browser by sending them simultaneously.

I've also found the following links helpful for finding the actual UTF 8 codes:

http://unicode.org/charts/PDF/U0000.pdf

https://seleniumhq.github.io/selenium/docs/api/py/_modules/selenium/webdriver/common/keys.html

0

Use below code :-

    String selectAll = Keys.chord(Keys.ALT, "s");
    driver.findElement(By.xpath("YOURLOCATOR")).sendKeys(selectAll);

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Thanks for helping, i do not have the keys.chord function in R, and i'm not targeting an element specifically, i'm targeting a prompt that appears in explorer when i click on "export as CSV", the prompt asks if i want to open or save the file. Pressing ALT+S on my keyboard solves the problem but i would a method send that key combination to my RSelenium web driver – user5822712 Aug 10 '17 at 14:28