require 'watir-webdriver' # get watir gem from watir.com # get chromedriver.exe from google and put it on Path. class K5 attr_accessor :name, :password, :sleep_value, :b def initialize @name = 'trane' @password = 'boogit' @sleep_value = 3 # seconds to wait for page to load sleep @sleep_value # Give page time to load end def login Watir::default_timeout = 200 @b = Watir::Browser.new :chrome # assumes chromedriver.exe is on the path. @b.goto 'kuro5hin.org' sleep 3 # Give page time to load, and don't stress the site. @b.text_field(:name => 'uname').when_present.set @name @b.text_field(:name => 'pass').when_present.set @password @b.button(:name => 'login').when_present.click sleep @sleep_value # Give new page time to load @b.title end def review_hidden_comments l = @b.link :text => 'Review Hidden Comments' puts "Can't find 'Review Hidden Comments' link." unless l.exists? l.click Watir::Wait.until {@b.body.exists?} sleep @sleep_value # Give page time to load. puts @b.title # move to search box Watir::Wait.until {@b.text_field(:name => 'string').exists?} searchbox = @b.text_field :name => 'string' searchbox.when_present.set ' ' # press tab 7 times to get to the first hidden comment, then click the link @b.send_keys "\t\t\t\t\t\t\t\n" sleep @sleep_value # select the ratings box # the name has different numbers at the end @b.select_list(:name => /rating_/).wait_until_present # TODO: put this in the loop that follows. s = @b.select_list :name => 'rating_0' (1..100).each do |i| s = @b.select_list :name => 'rating_' + i.to_s if s.exists? puts "rating_" + i.to_s + " found." break end end s.select 'Encourage (3)' @b.back # Now loop through the rest of the hidden comments (1..29).each do |j| Watir::Wait.until {@b.text_field(:name => 'string').exists?} searchbox = @b.text_field :name => 'string' searchbox.set ' ' tabstring = "\t\t\t\t\t\t\t" (1..j).each do |k| tabstring = tabstring + "\t\t\t\t" end @b.send_keys tabstring + "\n" sleep @sleep_value @b.select_list(:name => /rating_/).wait_until_present s = @b.select_list :name => 'rating_0' (1..100).each do |i| s = @b.select_list :name => 'rating_' + i.to_s if s.exists? puts "rating_" + i.to_s + " found." break end end s.select 'Encourage (3)' @b.back end end end if $0 == __FILE__ k5 = K5.new k5.login k5.review_hidden_comments k5.b.logout end