Challenge - 5 Problems
Page Factory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of element initialization in Page Factory
Consider the following Python Selenium code using the Page Factory pattern. What will be the output when accessing the
Assume the page contains a button with tag name
login_button element's tag name?Assume the page contains a button with tag name
button and id loginBtn.Selenium Python
from selenium.webdriver.common.by import By class LoginPage: def __init__(self, driver): self.driver = driver self.login_button = driver.find_element(By.ID, 'loginBtn') # Mock driver and element for demonstration class MockElement: def __init__(self, tag_name): self.tag_name = tag_name class MockDriver: def find_element(self, by, value): if by == By.ID and value == 'loginBtn': return MockElement('button') raise Exception('Element not found') page = LoginPage(MockDriver()) print(page.login_button.tag_name)
Attempts:
2 left
💡 Hint
Think about what tag name the mock element is initialized with.
✗ Incorrect
The mock element is created with tag name 'button', so accessing
tag_name returns 'button'.❓ assertion
intermediate1:30remaining
Correct assertion for Page Factory element visibility
You have a Page Factory element
Which assertion correctly verifies that this button is visible on the page?
submit_btn defined as:submit_btn = driver.find_element(By.ID, 'submit')
Which assertion correctly verifies that this button is visible on the page?
Attempts:
2 left
💡 Hint
Visibility means the element is shown on the page, not just present or enabled.
✗ Incorrect
The
is_displayed() method returns True if the element is visible to the user. This is the correct way to assert visibility.🔧 Debug
advanced2:30remaining
Identify the error in Page Factory element locator
Examine the following Page Factory element locator code snippet. What error will occur when running this code?
from selenium.webdriver.common.by import By
class HomePage:
def __init__(self, driver):
self.driver = driver
self.search_box = driver.find_element(By.CSS_SELECTOR, '#searchBox')
self.submit_btn = driver.find_element(By.ID, 'submitBtn')
def search(self, text):
self.search_box.send_keys(text)
self.submit_btn.click()Attempts:
2 left
💡 Hint
Think about what happens if the elements are not present on the page.
✗ Incorrect
If the elements with given locators are not found, Selenium raises NoSuchElementException at runtime.
❓ framework
advanced2:00remaining
Best practice for Page Factory element initialization
Which of the following is the best practice to initialize Page Factory elements in Selenium with Python to improve code readability and maintainability?
Attempts:
2 left
💡 Hint
Dynamic locating helps avoid stale element references and improves clarity.
✗ Incorrect
Using
@property decorators allows elements to be located fresh each time they are accessed, reducing stale element errors and improving maintainability.🧠 Conceptual
expert3:00remaining
Why use Page Factory pattern in Selenium tests?
Which of the following best explains the main advantage of using the Page Factory pattern in Selenium test automation?
Attempts:
2 left
💡 Hint
Think about how Page Factory helps manage code structure.
✗ Incorrect
Page Factory pattern helps keep element locators and page interactions organized separately from test logic, making tests easier to read and maintain.