Reputation: 205
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?
Upvotes: 11
Views: 9936
Reputation: 71
try browse.send_keys :return
found it here http://watir.com/guides/special-keys/
Upvotes: 7
Reputation: 5203
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.
Upvotes: 0
Reputation: 57262
browser.send_keys :enter
should do the job. Please provide link to the page, link to a similar page, or relevant HTML.
Upvotes: 11