How to simulate CTRL+Click with watir-webdriver?

寵の児 提交于 2019-12-21 18:47:14

问题


I want to simulate ctrl keydown and ctrl keyup.

My use-case is the following:

The user can select from a list (build with a table) multiple elements by pressing CTRL key and clicking on the desired row. When the CTRL key is released an AJAX call will be made.

I need a watir test to simulate this. How can i do this ? Any ideas ? I would need a solution that works under Linux

Thanks a lot.


回答1:


I believe the best way to send comands would be to do the following:

require 'watir-webdriver'

browser.send_keys[:control].send_keys[: arrow_up] browser.send_keys[:control].send_keys[: arrow_down]

If you want to check out some more key options here is a link:

Link to other key stroke options

Hope this helps!




回答2:


Realising this is old, but the original question didn't quite get answered, the way I have completed this is to do:

browser.a.click(:control)

If you are on a mac system you may want to use :command.

See http://watir.com/guides/special-keys/




回答3:


After some playing around with Ruby 1.9.2 and the Watir Webdriver I found this worked for sending multiple keys to the browser simultaneously:

browser.send_keys [:alt, :arrow_left]

OS: Win64 Browser: Firefox



来源:https://stackoverflow.com/questions/5858699/how-to-simulate-ctrlclick-with-watir-webdriver

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