A Base Page Class is a common parent class that holds shared methods and properties for all page classes. It helps avoid repeating code and makes tests easier to maintain.
Click to reveal answer
beginner
Why do we use locators in the Base Page Class?
Locators find elements on a web page. In the Base Page Class, we store common locators or methods to find elements so all pages can reuse them safely and clearly.
Click to reveal answer
intermediate
Example method in Base Page Class: How to wait for an element to be visible?
Use WebDriverWait with expected_conditions. For example, a method like wait_for_element(locator) waits until the element is visible before continuing.
Click to reveal answer
intermediate
What is the benefit of having a Base Page Class when the website changes?
When locators or common actions change, you update only the Base Page Class. This fixes all page classes that use it, saving time and reducing errors.
Click to reveal answer
beginner
How does the Base Page Class improve test readability?
It groups common actions like clicking or typing into named methods. Tests read like simple instructions, making them easier to understand and follow.
Click to reveal answer
What is the main purpose of a Base Page Class in Selenium?
ATo write test assertions
BTo run tests faster
CTo replace the WebDriver
DTo store common methods and locators for all pages
✗ Incorrect
The Base Page Class holds shared methods and locators to avoid repeating code across page classes.
Which Selenium feature is commonly used in Base Page Class to wait for elements?
AWebDriverWait with expected_conditions
Btime.sleep()
CJavaScript alerts
DBrowser cookies
✗ Incorrect
WebDriverWait with expected_conditions waits smartly for elements to appear, improving test reliability.
Where should you update locators if the website changes?
AIn the browser settings
BIn each test script
CIn the Base Page Class
DIn the test report
✗ Incorrect
Updating locators in the Base Page Class updates all page classes that use them, making maintenance easier.
Which of these is NOT a benefit of using a Base Page Class?
AReduces code duplication
BAutomatically fixes broken tests
CImproves test readability
DSimplifies maintenance
✗ Incorrect
The Base Page Class helps organize code but does not automatically fix broken tests.
What should a Base Page Class NOT contain?
ATest assertions
BCommon page actions like click or type
CLocator definitions
DWait methods for elements
✗ Incorrect
Assertions belong in test scripts, not in the Base Page Class which focuses on page actions and locators.
Explain what a Base Page Class is and why it is useful in Selenium testing.
Think about how to avoid repeating code for every page.
You got /4 concepts.
Describe how you would implement a method in the Base Page Class to wait for an element to be visible.
Focus on waiting smartly instead of using fixed delays.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a BasePage class in Selenium Python testing?
easy
A. To group common web page actions and locators for reuse
B. To store test data for different test cases
C. To define the browser settings and capabilities
D. To generate test reports automatically
Solution
Step 1: Understand the role of BasePage
The BasePage class is designed to hold common actions and locators shared by multiple page classes.
Step 2: Compare with other options
Storing test data, browser settings, or generating reports are not responsibilities of BasePage.
Final Answer:
To group common web page actions and locators for reuse -> Option A
Quick Check:
BasePage groups common actions [OK]
Hint: BasePage holds shared page methods and locators [OK]
Common Mistakes:
Confusing BasePage with test data storage
Thinking BasePage manages browser setup
Assuming BasePage creates reports
2. Which of the following is the correct way to define a locator tuple in a BasePage class?
easy
A. submit_button = (By.ID, 'submit')
B. submit_button = ['id', 'submit']
C. submit_button = {'id': 'submit'}
D. submit_button = By.ID('submit')
Solution
Step 1: Recall locator tuple syntax
Locator tuples use the format (By.<METHOD>, 'value'), e.g., (By.ID, 'submit').
Step 2: Check each option
submit_button = (By.ID, 'submit') matches the tuple format. The other options use wrong data structures or invalid syntax.
Final Answer:
submit_button = (By.ID, 'submit') -> Option A
Quick Check:
Locator tuple = (By.METHOD, 'value') [OK]
Hint: Locator tuples always use parentheses and By constants [OK]
Common Mistakes:
Using lists or dicts instead of tuples for locators
Calling By.ID as a function
Missing parentheses around locator tuple
3. Given this BasePage method, what will page.get_title() return if the browser's current page title is "Welcome Page"?
4. Identify the error in this BasePage method and how to fix it:
class BasePage:
def __init__(self, driver):
self.driver = driver
def click_element(locator):
element = self.driver.find_element(*locator)
element.click()
medium
A. Using find_element instead of find_elements
B. Missing 'self' parameter in click_element method
C. Locator should be a string, not a tuple
D. element.click() should be element.click
Solution
Step 1: Check method parameters
Instance methods must have 'self' as the first parameter. Here, click_element lacks 'self'.
Step 2: Understand impact
Without 'self', calling click_element will cause a TypeError because 'self.driver' is undefined.
Final Answer:
Missing 'self' parameter in click_element method -> Option B
Quick Check:
Instance methods need 'self' first [OK]
Hint: Always include 'self' as first method parameter [OK]
Common Mistakes:
Forgetting 'self' in instance methods
Confusing find_element with find_elements
Misunderstanding locator types
Using method call without parentheses
5. You want to create a BasePage method is_element_visible that returns True if an element is visible and False if not, without raising exceptions. Which is the best way to implement it?
hard
A. Use driver.page_source to search for element HTML string
B. Call find_element and return True without exception handling
C. Use try-except to catch NoSuchElementException and return False if caught
D. Use find_elements and check if list length is greater than zero
Solution
Step 1: Understand element visibility check
Using find_element raises NoSuchElementException if element not found, so we must handle it.
Step 2: Use try-except for safe check
Try to find element and check is_displayed(). If exception occurs, return False safely.
Final Answer:
Use try-except to catch NoSuchElementException and return False if caught -> Option C
Quick Check:
Try-except handles missing element safely [OK]
Hint: Wrap find_element in try-except to avoid exceptions [OK]
Common Mistakes:
Not handling exceptions causing test failure
Assuming find_elements always returns visible elements
Searching page_source is unreliable and slow
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.