如何在 Capybara 中使用 send_keys 发送向下箭头

11

我有一个特殊的列表框,最好是通过发送向下箭头和按Enter键来自动化。

我可以像这样按Enter键:

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

如何编写向下箭头命令?

5个回答

13

我不知道为什么之前错过了它,但那个解决了问题。谢谢! - TangibleDream
也许以前不同,但今天应该使用 send_keys 而不是 sendkeys - Jason Swett

2
find('#element_id').send_keys :arrow_down

1
这些答案可能与驱动程序有关。我正在使用Apparition js驱动程序(即,它是capybara的插件),可以正常工作的神奇代码如下:
find("input[type='search']").send_keys(:down).send_keys(:enter)

使用Capybara 3.33.0

使用Apparition JS driver (capybara插件)版本0.6.0


0
如果有人在2023年来到这里,就是sendkeys :down(不是:arrow_down)

-1
这些天(Capybara版本2.5+),你可以通过以下方式模拟<enter>键:
find('.selector').set("text\n")

\n 是关键。我认为你应该能够以非常相似的方式模拟向下箭头。


这并没有实际回答下箭头部分。 - Jason Swett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接