Tag Archive for 'Ruby Programming Code'

Shortcode Search Automator: A Ruby Script Using Watir

Here is my first attempt at a ruby script. Ugly? Probably. Functional? Absolutely! Hoorayy!
Also see: Watir @ Sourceforge

#!/usr/bin/env ruby
#--------------------------------------------------------------#
# ShortCodeSearch v1.0 by Alex Yule
# USShortcodes.com Shortcode Search Automator written by Alex Yule on 6/29/06
#
# Adapted from Simple Google test written by Jonathan Kohl   10/10/04
# Purpose: to test availability of shortcodes at usshortcodes.com
#   * entering text into a text field
#   * clicking a button
#   * checking to see if a page contains text.
#----------------------------------------------------------------#

require 'watir'   # the watir controller

#define test_code method--takes a code
def test_code(code)
   # set a variable
   test_site = 'http://www.usshortcodes.com'

   # open the IE browser
   ie = Watir::IE.new

   # print some comments
   # puts "## Beginning of #{code} test"

   #puts "Step 1: go to the test site: " + test_site
   ie.goto(test_site)
   #puts "Action: entered " + test_site + " in the address bar."

   ie.text_field(:name, "shortcode").set(code)       # shortcode is the name of the search field
   #puts "Action: entered #{code} in the search field"

   ie.button(:name, "single").click   # "single" is the name of the Search button

   if ie.contains_text("Login to BUY NOW.")   #Test for availability
       puts "Shortcode #{code} Available!!!"
       ie.close
   else
      puts "Shortcode #{code} taken..."
      ie.close
   end
end

s = ""
  while s != "end" #conditional loop
      print "enter code: "
      s = gets.chomp #take code input
      if s != "end" #check to see if program should end
	test_code(s) #check the code
	end
  end



FireStats icon Powered by FireStats