Q. How do I gem install Watir behind a proxy server?

A. Set an environment variable for your proxy from the command line …

set HTTP_PROXY=http://my.work.proxy:8080
gem install watir
Read More

Q. How do I require all ruby files in the current directory?

A. Iterate over the directory using the File class …
Example watir:

dir = File.dirname(__FILE__)
 Dir[File.expand_path("#{dir}/*.rb")].uniq.each do |file|
  require file
 end
Read More

Q. How do I close all other browsers except my current process?

A. Use .close_others method …
Example watir:

@b.close_others
Read More

Q. How do I detect if Internet Explorer is already running inside a watir script?

A. Use %x{} to run a sub process that calls tasklist.exe …
Example watir:

if %x[tasklist /FI "IMAGENAME eq IEXPLORE.EXE" /NH] =~ /IEXPLORE/ then
  puts "browser IS running"
else
  puts "no browsers running"
end
Read More

Q. How do I find the selected element in a combo box?

A. Use the select_list comand in conjunction with the getSelectedItems command
Example html:

<select name="watirCombo">
     <option value="0" selected>(please select:)</option>
     <option value="1">Option 1</option>
     <option value="2">Option 2</option>
     <option value="3">Option 3</option>
     <option value="other">Other</option>
</select>

Example watir:

 @b.goto('http://justaddwatir.com/watir/test_html/tc_0001_0100/test_0021.html')
 combo_items = @b.select_list(:name, "watirCombo").getSelectedItems
 puts combo_items
Read More