1
votes

I am new to watir webdriver and ruby. In my first scipt i am trying to type in a search string and trigger the click action on what looks like a button but by element inspection does not appaear to be a button. My watir script keeps failing to click on the search button after inserting the search string.

None of the following three options worked.
 browser.a(:id=> "search0_SearchIcon").submit
 browser.button(:id=> "search0_SearchIcon").submit
 browser.div(:id=> "header").div(:class=> "head-container").div(:class=> "search-field").button(:class => "rb-search-button js-rb-search-button").click

*******Test target code is listed below****

</div>
    <div class="search-field">
        <input accesskey="s" aria-autocomplete="list" aria-haspopup="true" autocomplete="off" class="js-rb-search-input" id="rbSearchInput" name="rbSearchInput" role="textbox" type="text" value="" />
        <a id="search0_SearchIcon" class="rb-search-button js-rb-search-button"></a>
        <form id="GeneralSearchForm" method="GET" action="/Search">
          <input name="query" type="hidden" id="rbSearchInputHidden" class="js-rb-search-input-hidden"  />
        </form>
    </div>
  </div>
************
1

1 Answers

2
votes

There are two things about your 'button':

  1. It is a link, therefore you need to use the a or link method.
  2. To click a link, you use the click method (not the submit method).

Depending on your personal preferences, either of the following should click the 'button':

browser.a(:id => "search0_SearchIcon").click

or

browser.link(:id => "search0_SearchIcon").click