How to send simultaneous keys in RSelenium ALT+S to web driver?

折月煮酒 提交于 2020-06-27 15:22:16

问题


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?


回答1:


Use below code :-

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

Hope it will help you :)




回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/45615659/how-to-send-simultaneous-keys-in-rselenium-alts-to-web-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!