Automating Internet Explorer with Ruby: Watir  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Ruby
Written by David Mullet   
Thursday, 21 June 2007

{mos_sb_discuss:50}

A reader has asked about automating Internet Explorer (IE) with Ruby. While you can do this using the win32ole library, I strongly recommend using the watir library instead.



WATIR (pronounced "water") stands for "Web Application Testing in Ruby". Watir is "a free, open-source functional testing tool for automating browser-based tests of web applications."

Though it's designed for driving IE to test web applications, Watir is also very handy for automating IE in non-test scenarios. It leverages the win32ole library under the hood, but provides objects and methods that simplify the process.

To use Watir, first install the watir gem. Open up a Command Prompt and type the following...

gem install watir

...then, in your script, require the watir library...

require 'watir'

To create an instance of IE and navigate to a website...

ie = Watir::IE.new
ie.goto('http://rubyonwindows.blogspot.com')


To click on a link...

ie.link(:text, "win32ole").click
ie.link(:url, 'http://rubyonwindows.blogspot.com/search/label/win32ole').click


To input text into a text field...

ie.text_field(:name, 'login').set('MyLogin')

To select an option from a drop-down list...

ie.select_list( :name , "HallOfFame").select("Dave Concepcion")

To click a button... 

Read more


User reviews

Average user rating from: 1 user(s)

Overall rating
4.0
 

Add new review



0 of 0 people found the following review helpful

Generic method for select list, Tuesday, 12 January 2010

Written by rashmi

Overall rating
4.0
Hi, I want to create generic method to select an item from the list.

require 'watir' # the watir controller
require 'rubygems'
ie = Watir::IE.start("http:// ")
ie.maximize()

oselectionbox=ie.select_list(:name,"EmailComObj")
itemtobeselected = "ABMailer"

def selectionbox_set(oselectionbox,itemtobeselected)
sselectionbox= oselectionbox.to_s

#select the required item from the list
if oselectionbox.includes?()
sslectionbox.select itemtobeselected
end

end

call selectionbox_set(oselectionbox,itemtobeselected

 

But it is showing an error when I execute it. Pl help somebody to update the script.
Was this review helpful to you? yes     no


Powered by jReviews

Last Updated ( Monday, 25 June 2007 )
 
< Prev   Next >