How do I simulate hitting enter in an input field with Capybara and ChromeDriver?

Solution 1:

find('#q_name').native.send_keys(:return)

works for me. I dont have a name or id for my field but the type is input so i used something like

find('.myselector_name>input').native.send_keys(:return)

works perfectly fine!

Solution 2:

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

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

The \n (new line) is the very important bit here.

Solution 3:

Usually when you run page.execute_script, you get the same results as if you were running that in the page console. Try running that manually in the console and see if you get the expected results. That is usually what I do.. craft the needed js code in the browser console window and paste it into the capybara code when it is working, using execute_script.