Once Watir is installed, along with Ruby and the Ruby DevKit (instructions for which are at www.watir.com), I was able to write out the following after reading their basic manual:

require “watir-webdriver”
browser = Watir::Browser.new :ff
browser.goto “google.com”
browser.link(:text => “Images”).click
browser.text_field(:name => “q”).set “plane”
browser.button(:value => “Search by image”).click

I saved it to a .rb file and ran it: ruby google_search.rb 

Is there any problem with this example?

Yes, there is.  It works, for now.  That’s the problem.  It’s entirely too brittle.  In fact the example that comes with Watir doesn’t work.  Google has changed their value for the Search button since the documentation was written. 

The Watir example used a value of “Search Images” – which has since changed to “Search by image” – if you use this type of automation text will no doubt change often.  It’s best to use CSS ID’s or Classes as often as you can. 

I’m not sure yet if Watir supports ID’s, i’m sure it does.  But I’ll need to dig into it further

Leave a Reply

Your email address will not be published. Required fields are marked *