0
0
Selenium Pythontesting~20 mins

Page class structure in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Page Class Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple Page class method
Given the following Page class method, what will be the output when calling get_title() if the page title is "Welcome Page"?
Selenium Python
class HomePage:
    def __init__(self, driver):
        self.driver = driver
    def get_title(self):
        return self.driver.title

# Assume driver.title returns "Welcome Page"
ANone
B"home page"
C"Welcome Page"
DRaises AttributeError
Attempts:
2 left
💡 Hint
Think about what the driver.title property returns.
assertion
intermediate
2:00remaining
Correct assertion for verifying page URL
Which assertion correctly verifies that the current page URL contains the substring "dashboard" in a Page class test method?
Selenium Python
def test_dashboard_page(self):
    current_url = self.driver.current_url
    # Assertion goes here
Aassert "dashboard" in current_url
Bassert current_url == "dashboard"
Cassert current_url.contains("dashboard")
Dassert current_url.index("dashboard")
Attempts:
2 left
💡 Hint
Check Python syntax for substring containment.
locator
advanced
2:00remaining
Best locator strategy for a login button
Which locator is the best practice to find a login button with id="loginBtn" in a Page class?
Aself.driver.find_element(By.XPATH, "//button[@id='loginBtn']")
Bself.driver.find_element(By.ID, "loginBtn")
Cself.driver.find_element(By.CSS_SELECTOR, "button#loginBtn")
Dself.driver.find_element(By.CLASS_NAME, "loginBtn")
Attempts:
2 left
💡 Hint
Using ID is usually the fastest and most reliable locator.
🔧 Debug
advanced
2:00remaining
Identify the error in this Page class method
What error will occur when running this method in a Page class?
Selenium Python
def click_submit(self):
    submit_button = self.driver.find_element(By.ID, "submitBtn")
    submit_button.click()
AAttributeError because 'driver' is None
BNoSuchElementException because element not found
CTypeError because click() is called incorrectly
DSyntaxError due to missing comma in find_element arguments
Attempts:
2 left
💡 Hint
Check the syntax of the find_element method call.
framework
expert
3:00remaining
Page class design for test maintainability
Which design choice best improves maintainability of Page classes in a Selenium Python test framework?
AStore all locators as class-level constants and use methods to interact with elements
BHardcode XPath strings inside each test method for flexibility
CUse global variables for locators and access them in Page classes
DWrite all Selenium commands directly in test methods without Page classes
Attempts:
2 left
💡 Hint
Think about how to keep locators organized and reusable.