Created
March 7, 2016 07:06
-
-
Save flyfy1/2b4384b1c60b6e28a9e6 to your computer and use it in GitHub Desktop.
Check the Application status for Singapore Permanent Residence. Used to work long time ago.. not sure if it is still working now.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'selenium-webdriver' | |
# Configs | |
FIN = "YOUR_FIND_NUMBER" | |
APPLICATION_NUMBER = "YOUR-PR-APPLICATION-NUMBER" | |
APPNUM_ARR = APPLICATION_NUMBER.split "-" | |
# driver = Selenium::WebDriver.for :phantomjs, args:"--ignore-ssl-errors=true" | |
driver = Selenium::WebDriver.for :chrome | |
wait = Selenium::WebDriver::Wait.new(:timeout => 2) | |
class DriverWrapper | |
def initialize(driver) | |
@driver = driver | |
end | |
def method_missing(method_name, *args, &blk) | |
@driver.send(method_name,*args,&blk) | |
end | |
def select(selector_type,selector_val,option_value) | |
select = @driver.find_element(selector_type, selector_val) | |
options = | |
select.find_elements(:tag_name, "option") | |
.select {|opt| opt.attribute('value') == option_value} | |
options[0].click | |
end | |
end | |
driver = DriverWrapper.new(driver) | |
driver.get "https://ienquiry.ica.gov.sg/public/selectService.do" | |
wait.until{driver.find_element(:name, 'service')} | |
driver.find_element(:xpath, '//*[@id="serviceSelection"]/select/option[@value="PR"]').click | |
wait.until {driver.find_element(:id,'VCHECK').text.include? "Particulars of Enquirer"} | |
driver.find_element(:name, 'enquiryDetailFin') | |
.send_keys(FIN) | |
driver.select(:id, 'selDay','31') | |
driver.select(:id, 'selMonth','01') | |
driver.select(:id, 'selYear','1990') | |
driver.find_element(:name, "VSubmit").click | |
wait.until{not driver.find_element(:id,'VCHECK').text.include?("Particulars of Enquirer")} | |
driver.find_element(:name, 'prOpt1Fin') | |
.send_keys(FIN) | |
4.times do |i| | |
driver.find_element(:name, "prOpt1InvitationRef#{i+1}") | |
.send_keys(APPNUM_ARR[i]) | |
end | |
driver.find_element(:xpath, '//*[@id="submit"]/input[1]').click | |
wait.until{ driver.find_element(:id,'main').text.include?("Application Details") } | |
status = driver.find_element(:xpath, '//*[@id="main"]/table[2]/tbody/tr[2]/td[3]').text | |
application_date = driver.find_element(:xpath, '//*[@id="main"]/table[2]/tbody/tr[2]/td[5]').text | |
remark = driver.find_element(:xpath, '//*[@id="main"]/table[2]/tbody/tr[2]/td[6]').text | |
puts "#{FIN} #{APPLICATION_NUMBER}" | |
puts "status: #{status}; application date: #{application_date}" | |
puts "Remark: #{remark}" | |
# driver.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment