0
0
Selenium Pythontesting~20 mins

Base page class in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Base Page Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium base page class method?
Consider this base page class method that waits for an element to be visible and returns its text.
What will be printed when calling get_element_text() if the element is visible and contains 'Hello World'?
Selenium Python
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class BasePage:
    def __init__(self, driver):
        self.driver = driver

    def get_element_text(self, locator):
        element = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located(locator)
        )
        return element.text

# Usage example:
# base_page = BasePage(driver)
# print(base_page.get_element_text((By.ID, 'greeting')))
A"Hello World"
B"" (empty string)
CTimeoutException
DNoSuchElementException
Attempts:
2 left
💡 Hint
The method waits until the element is visible before getting text.
locator
intermediate
1:30remaining
Which locator is best practice for a base page class method?
You want to write a base page method that clicks a button reliably. Which locator is best to use?
ABy.ID, "submit"
BBy.CSS_SELECTOR, "button.submit-btn"
CBy.XPATH, "//button[text()='Submit']"
DBy.CLASS_NAME, "btn"
Attempts:
2 left
💡 Hint
IDs are unique and fast to locate.
assertion
advanced
1:30remaining
Which assertion correctly verifies a page title in a base page test?
You want to assert that the page title is exactly 'Dashboard'. Which assertion is correct?
Selenium Python
def test_page_title(base_page):
    title = base_page.driver.title
    # Which assertion below is correct?
Aassert 'Dashboard' in title
Bassert title == 'Dashboard'
Cassert title.startswith('Dashboard')
Dassert title != 'Dashboard'
Attempts:
2 left
💡 Hint
Exact match is needed for this test.
🔧 Debug
advanced
2:00remaining
Why does this base page method raise TimeoutException?
This base page method waits for an element to be clickable but raises TimeoutException every time.
What is the likely cause?
Selenium Python
def click_element(self, locator):
    element = WebDriverWait(self.driver, 5).until(
        EC.element_to_be_clickable(locator)
    )
    element.click()
AThe wait time of 5 seconds is too long
BThe element is visible but disabled
CThe locator is incorrect or does not match any element
DThe driver is not initialized
Attempts:
2 left
💡 Hint
TimeoutException means the condition was never met.
framework
expert
2:30remaining
What is the main benefit of using a base page class in Selenium tests?
Choose the best explanation for why a base page class is used in Selenium test automation frameworks.
AIt allows running tests in parallel without conflicts
BIt automatically generates test reports after each test run
CIt replaces the need for explicit waits by handling all waits internally
DIt centralizes common page actions and locators to reduce code duplication and improve maintainability
Attempts:
2 left
💡 Hint
Think about code reuse and organization.