2

As part of a Selenium integration test, I wrote the two following lines in Ruby to simulate entering an e-mail address into a text field and "moving the focus away":

  @driver.find_element(:id, "user_email").send_keys "user@example.com"
  @driver.find_element(:id, "some_other_element").click

The second line is not generic enough, because some_other_element might be unknown or non-existent. Thus, I wanted to replace the action of clicking another element with a TAB keystroke:

  @driver.find_element(:id, "user_email").send_keys :tab

However, this does not seem to work, the element user_email does not lose its focus as expected. Also replacing :tab with "\xEE\x80\x84" does not help. Does anyone know what could be wrong here? How can I move the focus away of an element without simulating a click somewhere else?

Thanks for any help,
Dominik

dokaspar
  • 8,186
  • 14
  • 70
  • 98

2 Answers2

1

I don't know how to do it without simulating a click, but clicking on <body> worked for me. This solution may be generic enough.

WilQu
  • 7,131
  • 6
  • 30
  • 38
0

I think this should works well. Give it a try.

find('.myselector_name').native.send_keys(:tab)

Reference to answer is How do I simulate hitting enter in an input field with Capybara and ChromeDriver?

Community
  • 1
  • 1
Aamir
  • 16,329
  • 10
  • 59
  • 65