How do I send_keys a down arrow in capybara
Asked Answered
L

5

11

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?

Lacedaemon answered 17/12, 2012 at 15:8 Comment(0)
E
13

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

Emendate answered 17/12, 2012 at 15:34 Comment(2)
I don't why I missed it before, but that nailed it. Thanks!Lacedaemon
Maybe it was different before, but today it's send_keys, not sendkeysVariscite
V
2
find('#element_id').send_keys :arrow_down
Variscite answered 10/8, 2019 at 17:11 Comment(0)
U
1

These answers are dependent on the driver I believe. I am using the Apparition js driver (i.e., it's a plugin for capybara) and the magic code that works is this:

find("input[type='search']").send_keys(:down).send_keys(:enter)

Using Capybara 3.33.0

Using the Apparition JS driver (plugin for capybara) version 0.6.0

Untruth answered 16/2, 2021 at 17:2 Comment(0)
S
0

If anyone lands here in 2023, it's sendkeys :down (not :arrow_down)

Stratton answered 6/10, 2023 at 16:27 Comment(0)
K
-1

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.

Kabul answered 23/12, 2016 at 16:22 Comment(1)
This doesn't actually answer the down-arrow partVariscite

© 2022 - 2024 — McMap. All rights reserved.