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
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.