Search code examples
rubymechanize

Clicking a button with Ruby Mechanize


I have a particularly difficult form that I am trying to click the search button and can't seem to do it. Here is the code for the form from the page source:

<input type="image" name="" src="http://images.example.com/WOKRS53B4/images/search.gif" align="absmiddle" border="0" onclick="return check_form_inputs('UA_GeneralSearch_input_form','search');" title="Search" alt="Search" class="">

I am trying to do the standard mechanize click action:

login_page = agent.click(homepage.link_with(:text => "Search"))

Is this because the button uses javascript? If so, any suggestions?


Solution

  • It is not a link, it is a button. What you need to do is look for the form (for example, with form_with) and then look for the ImageButton and submit it.