Created
August 10, 2014 21:29
-
-
Save jljohnstone/7899bfd039b55b521d80 to your computer and use it in GitHub Desktop.
Example Watir/CSV script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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