The Page Object Model helps keep the code organized by separating the page structure and actions from the test logic. This makes tests easier to maintain when the UI changes.
class LoginPage: def __init__(self): self.page_title = "Login Page" def get_title(self): return self.page_title page = LoginPage() print(page.get_title())
The method get_title() returns the string stored in the page_title attribute, which is "Login Page".
Using a unique ID attribute with a CSS selector is the most stable and maintainable locator strategy. Absolute XPath is fragile, text matching can break if text changes, and class names may not be unique.
page = DashboardPage() actual_title = page.get_title()
To verify the page title exactly matches 'Dashboard', use equality assertion. Option A checks only if 'Dashboard' is part of the title, which is less strict.
Creating a base test class that initializes page objects once per test class promotes reusability and reduces duplication. Instantiating inside each test method repeats code, and global variables can cause test interference.