canimus
5/28/2015 - 8:32 AM

Hackaton 1 Automation - Planit Perth

Hackaton 1 Automation - Planit Perth

require 'watir'
require 'selenium-webdriver'
require 'base64'
require 'colorize'
require 'awesome_print'

profile = Selenium::WebDriver::Firefox::Profile.new
# 2 means custom folder
profile['browser.download.folderList'] = 2
#Specify the custom download folder
profile['browser.download.dir'] = "/sw/apps/hackaton_1"
# specify the mime-type
profile['browser.helperApps.neverAsk.saveToDisk'] = "image/png"


b = Watir::Browser.new 
b.goto "http://linkedin.com"

b.element(id:"session_key-login").send_keys "youruser"
b.element(id:"session_password-login").send_keys Base64.decode64("encodedpassword")

b.element(id: "signin").click

b.element(id: "main-search-box").send_keys "test automation perth"
b.element(name: "search").click

# Results
result_count = b.element(xpath:"//div[@class='search-info']//strong[1]").text

puts "Candidates: #{result_count}"


# names
names = b.elements(xpath: "//ol[@id='results']//li")
images = b.elements(xpath: "//ol[@id='results']//li//img")

names.each_with_index {|x,i| 	
	  title = x.text.split("\n")
	  ap title
}

# Full Page Screenshot
#b.driver.save_screenshot "scn.png"

images.each_with_index {|p,i|
	begin 
		url = p.html.split(" ")[2].split("=")[1].gsub("\"","")
		`curl -o #{i}.jpg #{url}`		
	rescue NoMethodError
		puts "No url"
	end
}