Recall & Review
beginner
What is the Page Factory pattern in Selenium?
Page Factory is a design pattern in Selenium that helps initialize web elements easily using annotations, making tests cleaner and easier to maintain.
Click to reveal answer
beginner
How do you declare a web element using Page Factory in Python?
You define locators as class attributes using tuples with By, and use the @property decorator to lazily locate and return elements when first accessed.Click to reveal answer
intermediate
Why is Page Factory pattern preferred over traditional element locating?
Because it reduces code duplication, improves readability, and initializes elements only when they are used, which can improve test performance.
Click to reveal answer
intermediate
What is the role of lazy initialization in Page Factory?
It initializes web elements lazily when accessed so they can be used directly without calling find_element repeatedly each time.
Click to reveal answer
beginner
Give a simple example of a Page Factory class in Selenium Python.from selenium.webdriver.common.by import By
class LoginPage:
username_loc = (By.ID, 'username')
password_loc = (By.ID, 'password')
login_button_loc = (By.ID, 'login')
def __init__(self, driver):
self.driver = driver
@property
def username(self):
return self.driver.find_element(*self.username_loc)
@property
def password(self):
return self.driver.find_element(*self.password_loc)
@property
def login_button(self):
return self.driver.find_element(*self.login_button_loc)
def login(self, user, pwd):
self.username.send_keys(user)
self.password.send_keys(pwd)
self.login_button.click()Click to reveal answer
What does the Page Factory pattern help with in Selenium?
✗ Incorrect
Page Factory is used to initialize web elements efficiently in Selenium tests.
Which is used to lazily initialize elements in Page Factory (Python)?
✗ Incorrect
The @property decorator initializes web elements lazily when accessed in the Python Page Factory pattern.
In Page Factory, when are web elements initialized?
✗ Incorrect
Page Factory initializes elements lazily, meaning only when they are used.
Which of these is NOT a benefit of using Page Factory?
✗ Incorrect
Page Factory does not skip element checks; it initializes elements efficiently but does not skip validations.
What is the main purpose of locators in Page Factory?
✗ Incorrect
Locators are used to find web elements on the page for interaction.
Explain the Page Factory pattern and how it improves Selenium test code.
Think about how you find elements in Selenium and how Page Factory changes that.
You got /3 concepts.
Describe how you would implement a login page using the Page Factory pattern in Selenium Python.
Imagine the steps a user takes to log in and how to automate them.
You got /3 concepts.