Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from selenium import webdriver
- def get_credentials():
- """Get user credentials from a JSON file"""
- with open('auth.json', 'r') as f:
- auth = json.load(f)
- username = auth['username']
- password = auth['password']
- return username, password
- class LeapHandler:
- """Class to handle any interactions with Leap Card website"""
- def __init__(self):
- self.driver = webdriver.Chrome()
- self.driver.get('https://www.leapcard.ie/en/login.aspx')
- self.login()
- def get_login_elements(self):
- """Find and return elements necessary to log in"""
- username_id = 'ContentPlaceHolder1_UserName'
- password_id = 'ContentPlaceHolder1_Password'
- login_id = 'ContentPlaceHolder1_btnlogin'
- username_field = self.driver.find_element_by_id(username_id)
- password_field = self.driver.find_element_by_id(password_id)
- login_button = self.driver.find_element_by_id(login_id)
- return username_field, password_field, login_button
- def login(self):
- """Login into user account"""
- username_field, password_field, login = self.get_login_elements()
- username, password = get_credentials()
- username_field.send_keys(username)
- password_field.send_keys(password)
- login.click()
- def get_balance(self):
- """Return current Leap Card Balance"""
- balance = self.driver.find_element_by_css_selector('div.pull-left').text
- return balance
- if __name__ == '__main__':
- lh = LeapHandler()
- balance = lh.get_balance()
- print(f'LepaCard balance is €{balance}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement