Created
February 25, 2022 07:23
-
-
Save Pragith/61732bf3e0746ad90b8c6bd43fce60aa to your computer and use it in GitHub Desktop.
Citizenship Application Tracker - Selenium Automation (Headless / GUI)
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
import os, time, datetime | |
from termcolor import colored | |
from selenium import webdriver | |
from selenium.webdriver.firefox.options import Options | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import Select | |
from selenium.webdriver.common.by import By | |
URL = 'https://services3.cic.gc.ca/ecas/authenticate.do' | |
accounts = [ | |
{'name': 'Smith', 'uci': '123456789', 'dob': '2000-12-12'}, | |
{'name': 'Doe', 'uci': '123456789', 'dob': '2000-12-12'} | |
] | |
account = accounts[0] | |
def ID(val): | |
return driver.find_element(By.ID, val) | |
def CLASS(val): | |
return driver.find_element(By.CLASS_NAME, val) | |
def XPATH(val): | |
return driver.find_element(By.XPATH, val) | |
def SELECT(val): | |
return Select(driver.find_element(By.ID, val)) | |
print ('Opening URL...') | |
options = Options() | |
options.headless = True | |
driver = webdriver.Firefox(options=options) | |
driver.get(URL) | |
# Security page | |
print ('Security page...') | |
ID('agree').click() | |
XPATH('/html/body/main/div[2]/form/section/div[3]/input[1]').click() | |
# Authenticate page | |
print ('Authenticating...') | |
ID('idTypeLabel').click() | |
SELECT('idTypeLabel').select_by_value('1') | |
ID('idNumberLabel').send_keys(account['uci']) | |
ID('surnameLabel').send_keys(account['name']) | |
ID('dobDate').send_keys(account['dob']) | |
SELECT('cobLabel').select_by_value('205') | |
XPATH('/html/body/main/div[2]/form/div[22]/input[1]').click() | |
applicationStatus = XPATH('/html/body/main/div[2]/form/table/tbody/tr/td[2]/a').text | |
print(colored(f'Application Status:', 'red'), colored(applicationStatus, 'green')) |
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
import os, time, datetime | |
from base64 import b64encode, b64decode | |
from termcolor import colored | |
from selenium import webdriver | |
from selenium.webdriver.firefox.options import Options | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import Select | |
from selenium.webdriver.common.by import By | |
URL = 'https://cst-ssc.apps.cic.gc.ca/en/login' | |
accounts = [ | |
{'name': 'Smith', 'uci': '123456789', 'dob': '2000-12-12'}, | |
{'name': 'Doe', 'uci': '123456789', 'dob': '2000-12-12'} | |
] | |
password = b64decode(b'UHaJahZ2l34f0aEAxOt44DE4MTg=').decode('utf-8') | |
account = accounts[0] | |
def ID(val): | |
return driver.find_element(By.ID, val) | |
def CLASS(val): | |
return driver.find_element(By.CLASS_NAME, val) | |
def XPATH(val): | |
return driver.find_element(By.XPATH, val) | |
def SELECT(val): | |
return Select(driver.find_element(By.ID, val)) | |
print ('Opening URL...') | |
options = Options() | |
options.headless = True | |
driver = webdriver.Firefox(options=options) | |
driver.get(URL) | |
# Login page | |
print ('Signing in...') | |
time.sleep(3) | |
ID('uci-input').send_keys(account['uci']) | |
ID('password-input').send_keys(password) | |
ID('sign-in-submit-btn').click() | |
time.sleep(6) | |
# Dashboard page | |
print ('Loaded Dashboard') | |
applicationStatus = XPATH('/html/body/div/div[1]/main/div/div[1]/div[2]/p/strong').text | |
lastUpdated = XPATH('/html/body/div/div[1]/main/div/div[1]/div[1]/dl/dd/time').text | |
languageSkills = XPATH('/html/body/div/div[1]/main/div/section[2]/div/ul[1]/li[1]/details/summary/div[1]/p').text | |
backgroundVerification = XPATH('/html/body/div/div[1]/main/div/section[2]/div/ul[2]/li[1]/details/summary/div[1]/p').text | |
physicalPresence = XPATH('/html/body/div/div[1]/main/div/section[2]/div/ul[1]/li[2]/details/summary/div[1]/p').text | |
prohibitions = XPATH('/html/body/div/div[1]/main/div/section[2]/div/ul[2]/li[2]/details/summary/div[1]/p').text | |
citizenshipTest = XPATH('/html/body/div/div[1]/main/div/section[2]/div/ul[1]/li[3]/details/summary/div[1]/p').text | |
citizenshipCeremony = XPATH('/html/body/div/div[1]/main/div/section[2]/div/ul[2]/li[3]/details/summary/div[1]/p').text | |
print(colored(f'Application Status:', 'red'), colored(applicationStatus, 'green')) | |
print(colored(f'Last Updated:', 'red'), colored(lastUpdated, 'green')) | |
print(colored(f'Language Skills:', 'red'), colored(languageSkills, 'green')) | |
print(colored(f'Background Verification:', 'red'), colored(backgroundVerification, 'green')) | |
print(colored(f'Physical Presence:', 'red'), colored(physicalPresence, 'green')) | |
print(colored(f'Prohibitions:', 'red'), colored(prohibitions, 'green')) | |
print(colored(f'Citizenship Test:', 'red'), colored(citizenshipTest, 'green')) | |
print(colored(f'Citizenship Ceremony:', 'red'), colored(citizenshipCeremony, 'green')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment