水豚 send_keys 不发送点击事件?

Capybara send_keys without sending click event?

似乎在 Capybara 中使用 send_keys 总是首先在给定的输入上触发一个 click 元素。

有没有办法绕过这个,例如当我知道我已经将焦点设置到输入时(并且出于某种原因不想触发 click 事件)?

顺便说一下,我正在使用 PhantomJS。

Poltergeist 在向其发送密钥之前单击该元素以确保它是焦点元素 - https://github.com/teampoltergeist/poltergeist/blob/master/lib/capybara/poltergeist/client/browser.coffee#L365 . As you can see from the code the click is skipped if the element already contains a selection which is defined by https://github.com/teampoltergeist/poltergeist/blob/master/lib/capybara/poltergeist/client/browser.coffee#L365。因此,唯一支持跳过点击的方法是确保选择已经在您要将键发送到的元素中。