How do I send_keys a down arrow in capybara

2019-05-06 13:05发布

问题:

I have a special listbox that I could automate best by sending a down arrow and pressing enter.

I can press enter like so:

listbox_example = find(input, "listbox-example")
listbox-example.set("stuff")
#down arrow command goes here
listbox-example.native.send_keys :return

How do I write the down arrow command?

回答1:

If I remember correctly the correct way to send the down arrow command is to use arrow_down

So your code should look like this

listbox-example.native.sendkeys :arrow_down

If you would like a list of all the available keys that you can send, then docs are your friend here

http://www.ruby-doc.org/gems/docs/f/frameworks-capybara-0.2.18/SendKeys.html

EDIT: This link might have the intended content. https://www.omniref.com/ruby/gems/frameworks-capybara/0.2.18/symbols/SendKeys



回答2:

These days (Capybara version 2.5+) you can simulate <enter> key in the following way:

find('.selector').set("text\n")

The \n is key here. I think you should be able to simulate down arrow in a very similar way.