Course Content
Selenium Python First Script
Selenium Python First Script
0/2
HTML Form elements
HTML Form elements
0/1
Handle HTML Frames
Handle HTML Frames
0/2
Handling Dropdown Lists
Handling Dropdown Lists
0/2
Selenium Action class
Selenium Action class
0/1
Selenium Python for Beginners [ 2024 ]
About Lesson

OrangeHRM Login Page Object

Login Page UI Screenshot

OrangeHRM Login Screen

Use the developer tools to identify the web elements on the page.

Login Page Object

Encapsulate the web page in a class.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class LoginPage:
    """Page Object for the Login page"""
    
    def __init__(self, driver):
        self.driver = driver
        self.username_locator = (By.NAME, 'username')
        self.password_locator = (By.NAME, 'password')
        self.login_button_locator = (By.CLASS_NAME, 'oxd-button')
        
    def load(self):
        # Replace domain with actual
        self.driver.get("https://<domain>/hrm/web/index.php/auth/login")
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(self.username_locator))
        
    def set_username(self, username):
        username_field = self.driver.find_element(*self.username_locator)
        username_field.clear()
        username_field.send_keys(username)
        
    def set_password(self, password):
        password_field = self.driver.find_element(*self.password_locator)
        password_field.clear()
        password_field.send_keys(password)
        
    def click_login_button(self):
        login_button = self.driver.find_element(*self.login_button_locator)
        login_button.click()
        
    def login(self, username, password):
        self.load()
        self.set_username(username)
        self.set_password(password)
        self.click_login_button()

Screenshot

OrangeHRM Login Page Object

Join the conversation