Skip to content

Instantly share code, notes, and snippets.

@ktemkin
Created September 24, 2014 02:09
Show Gist options
  • Save ktemkin/6693474edcc47d8a9fd1 to your computer and use it in GitHub Desktop.
Save ktemkin/6693474edcc47d8a9fd1 to your computer and use it in GitHub Desktop.
Simple Watir script for mass updating ID cards.
#!/usr/bin/env ruby
#
# Script to mass override assignment due dates for a given user.
#
#
require 'highline/import'
require 'watir-webdriver'
MAPPINGS = {
# user id => idcard number
1 => 290910000000000
}
#Get the username and password to use.
USERNAME = 'ktemkin'
PASSWORD = ask('Enter password:') { |q| q.echo = false }
# Create a new WebDriver front-end.
browser = Watir::Browser.new :chrome
#Log in.
browser.goto 'https://www.bumoodle.com/login/index.php'
browser.text_field(:id => 'username').set(USERNAME)
browser.text_field(:id => 'password').set(PASSWORD)
browser.button(:id => 'loginbtn').click
# Iterate through each of the IDs.
MAPPINGS.each do |uid, id_number|
#begin
#navigate to the profile page for the provided ID
browser.goto "https://www.bumoodle.com/user/editadvanced.php?id=#{uid}"
#expand the ID number tab
browser.link(:text => 'University IDs').click
#enter in the ID number
browser.text_field(:name => 'profile_field_idcard').set(id_number)
#and submit the form
browser.button(:id => 'id_submitbutton').click
#rescue Watir::Exception::UnknownObjectException
#end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment