This file contains 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 'mechanize' | |
def rand_array tam # array random de 0 y 1 | |
num = Proc.new{ rand(100)%2 } | |
ans = Array.new(tam, &num) | |
end | |
100.times do # submit 100 encuestas | |
agent = Mechanize.new | |
page = agent.get "http://goo.gl/pJjx6" # Encuesta en google docs | |
############## Checkboxes y Radiobuttons ######## | |
check_names = page.form.checkboxes.collect{ |c| c.name}.uniq | |
check_names.each do |name| | |
boxes = page.form.checkboxes_with(name) # opciones de una preg | |
numbers = rand_array boxes.length | |
numbers.each_with_index{|i, index| boxes[index].check if i==1 }# marcando, opcion multiple | |
end | |
radio_names = page.form.radiobuttons.collect{ |r| r.name}.uniq | |
radio_names.each do |name| | |
radios = page.form.radiobuttons_with(name) # opciones de una preg | |
number = rand radios.length | |
page.form.radiobuttons_with(name)[number].check # marcando, opcion unica | |
end | |
################################################# | |
page.form.click_button # submit encuesta | |
agent = nil | |
end |