I’ve re-written this question so that it makes more sense.
Is there a way to enable Ruby to listen for a newly created (dynamic) select-list on a webpage and save that list into an array?
This would be the scenario:
- User Selects a Branch number, 02
- User selects a person type, missionary
- A new dynamic select list of missionary names is generated
Ruby would need to capture the dynamically created list of names and save them into an array. This is the code thus far:
missionaries = Array.new
browser.select_list(:id,'branch_select').select_value('02')
browser.select_list(:id,'user_type_select').select_value('1') # 1 = Missionary
browser.select_list(:index,2).click # <-This is the dynamically created list
missionaries = browser.select_list(:index,2) # <-This is just a guess, doesn't work
puts "Missionary List: " + missionaires.to_s # <-Prints to verify list saved
What this actually prints to screen is this:
Missionary List: #<Watir::Select:0x147e54e>
OK, I’ve figured it out. The list was being dynamically populated by a JSON call. What I’ve had to do is first figure out what happens when the second list item is selected (in this case, missionaries). As soon as that was selected, a GET request was sent, then a JSON string was received.
The string had to be captured by Ruby using the open-uri gem/library. Then parsed using the json gem. After that I used regex to count the amount of times that a new id was found. Here’s the new code:
This would print the amount of missionaries found in the Branch, in this case 16.