#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #''SCRIPT NAME: Select_Random_Web_List_Value #'' #''SCRIPT CREATOR: Automated Testing Institute #'' #''SCRIPT OBJECTIVE: The objective of this script is to randomly select a value #'' from a web list box #''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' def selectRandomWebListValue(objIEArg) #Access the List Item #Note: The Math Test Application has a 'Select Number Sets' list item that has a Name property equal to 'numSets'. # This numSets object will be used. numSetsObject = objIEArg.document.all("numSets") #Get a collection of all list items (options objects) listItemCollection = numSetsObject.options #Get a count of the total number of items in the collection listItemCount = listItemCollection.length #Use random number generator to randomly select a list item index randomListIndex = rand(listItemCount) #Print the Index and the List Item Text to the screen puts "The index number of the item selected from the List Object is '" + randomListIndex.to_s + "' and the text of this option is: " + listItemCollection.item(randomListIndex).text #Click the random list item objIEArg.document.all("numSets").selectedIndex = randomListIndex end #Test the method #Load libraries require 'win32ole' #Declare Variables - Note: No need to declare variables in Ruby #Instantiate an Instance of IE objIE = WIN32OLE.new("InternetExplorer.Application") #Make the browser visible objIE.visible = "true" #Navigate to the desired website (Math Test Application is used) objIE.navigate "http://www.dijohn-ic.com/MathTestApplication1.html" sleep 2 listIndex = selectRandomWebListValue(objIE)