Last active
August 29, 2015 14:22
-
-
Save canimus/cd30509b297486dba62d to your computer and use it in GitHub Desktop.
Hackaton 1 Automation - Planit Perth
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 '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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment