View Sidebar
Forms Not Submitting With Watir?

Forms Not Submitting With Watir?

September 29, 2009 10:44 am1 comment

Watir, pronounced water, is an open-source (BSD) library for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.

Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.

A great use for Watir is to automate tedious form filling during development / developer testing.  Let’s say you have a simple form like the following to submit a search query to Google:

<form id="search_form" action="">
  <input name="q" value="derekhat" />
  <input type="submit" name="submit" />

The Ruby code to submit a form is pretty simply:

Browser.goto "file:///C:/Users/derek/Desktop/submit.html";
Browser.form(:id, "search_form").submit;

The only problem is that this won’t work in this case.  The reason:  there’s an input field called submit that hides the form’s submit method.  The workaround is easy:

Browser.goto "file:///C:/Users/derek/Desktop/submit.html";
Browser.button(:name, "submit").click;

Happy testing!

1 Comment