Skip to content

Instantly share code, notes, and snippets.

@jljohnstone
Created August 10, 2014 21:29
Show Gist options
  • Save jljohnstone/7899bfd039b55b521d80 to your computer and use it in GitHub Desktop.
Save jljohnstone/7899bfd039b55b521d80 to your computer and use it in GitHub Desktop.
Example Watir/CSV script
require 'csv'
require 'watir-webdriver'
######### If IE is required, comment out line 7 and uncomment line 10 #########
# Use default browser
browser = Watir::Browser.new
# Use Internet explorer
# browser = Watir::Browser.new :ie
###############################################################################
# Iterate through each row in the CSV file
CSV.foreach("data.csv") do |row|
# Change bing.com below
browser.goto 'bing.com'
# Find the id attribute for the field that should receive the value in
# column A of your spreadsheet. Change it as necessary below
browser.text_field(:id => 'sb_form_q').set row[0]
# Find the id attribute for the field that should receive the value in
# column B of your spreadsheet. Change it as necessary below and uncomment
# line 27
# browser.text_field(:id => 'input_id_2').set row[1]
# Find the id attribute for the submit button and update line 30
browser.button(:id => 'sb_form_go').click
# Delays the processing of the next row for 3 seconds
sleep 3
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment