11

I need to automate the action of hitting 'Enter' key on keyboard after entering a text in a text field. I tried @browser.send_keys :enter but that does not do the action. also have tried @browser.text_field(:name => 'q').send_keys :enter or @browser.text_field(:name => 'q').focus and then send_keys. But has not helped.

@browser.send_keys("{ENTER}")

does not help this too, this actually types ("{ENTER}")

Please let me know other ways of doing?

user1771980
  • 207
  • 3
  • 8

3 Answers3

11

browser.send_keys :enter should do the job. Please provide link to the page, link to a similar page, or relevant HTML.

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
7

try browse.send_keys :return found it here http://watirmelon.com/about/

  • 1
    Here is a [Full List of Special Keys](http://watirmelon.com/2011/07/19/sending-special-keys-to-watir-webdriver/) – TrinitronX Feb 21 '13 at 00:51
0

Given the HTML:

<input type="text" size="30" class="searchText" dojoattachpoint="_searchTextAP" id="xwt_widget_uishell_Header17_2_search_searchTextAP" dojoattachevent="onfocus:_onFocus_searchTextAP,onblur:_onBlur_searchTextAP, onkeyup:_onKeyUp_searchTextAP">

It looks like the element is listening for these events (via dojo): onfocus, onblur, onKeyUp

To trigger these events, you'll need to use something like this:

browser.text_field(:id => /.*searchTextAP$/).focus
browser.element(:id => 'someOtherElement').focus
browser.text_field(:id => /.*searchTextAP$/).fire_event "onkeyup"

If you want to submit the form, you probably need to click the submit button (since you mentioned hitting :enter):

browser.button(:type => 'submit').click

If you really wanted to just send the :enter key, one of the other answers should work.

TrinitronX
  • 4,959
  • 3
  • 39
  • 66