dokaspar
dokaspar

Reputation: 8624

Unable to send the TAB key during a Selenium integration test

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 "[email protected]"
  @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

Upvotes: 2

Views: 1053

Answers (2)

Aamir
Aamir

Reputation: 16977

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?

Upvotes: 0

WilQu
WilQu

Reputation: 7393

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.

Upvotes: 1

Related Questions