page-object-patterns

A set of Selenium patterns for organizing browser tests with the Page Object Model, a way to keep page interactions in reusable classes. It includes shared page behavior, reusable interface components, chained actions, and locator strategies.

In plain words
What is it for?
Use it to build Selenium page classes, share common browser actions, model reusable UI components, and write readable multi-step test code.
Why use it?
It reduces duplicated browser-test code and keeps selectors and page interactions in one place. That makes tests easier to read and maintain when a website changes.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/tugkanboz/awesome-cursorrules/page-object-patterns
Clone the repo
git clone --depth 1 https://github.com/tugkanboz/awesome-cursorrules

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,767 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01767
Opus 5 $0.00000 $0.00883
Sonnet 5 $0.00000 $0.00353
Haiku 4.5 $0.00000 $0.00177

Measured 3d ago against content hash 95a577555e07, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

page-object-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

example-structures/selenium-python/.cursor/rules/page-object-patterns.mdc · 215 lines

How it starts

The opening of the file, as written. The whole thing — 215 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Page Object Model Excellence

Advanced POM Architecture

  • Inheritance Hierarchy: BasePage class with common functionality
  • Component Pattern: Reusable UI components across pages
  • Fluent Interface: Method chaining for readable test code
  • Smart Locators: Dynamic locator strategies with fallbacks

Base Page Implementation

from typing import Optional, List, Union, Tuple
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import TimeoutException, StaleElementReferenceException
import logging

logger = logging.getLogger(__name__)

class BasePage:
    """Enhanced base page with advanced interaction methods."""
    
    def __init__(self, driver, timeout: int = 10):
        self.driver = driver
        self.wait = WebDriverWait(driver, timeout)
        self.timeout = timeout
        self.actions = ActionChains(driver)
    
    def find_element_safely(self, locator: Tuple[str, str], timeout: Optional[int] = None) -> Optional[WebElement]:
        """Find element with comprehensive error handling and retry logic."""
        timeout = timeout or self.timeout
        wait = WebDriverWait(self.driver, timeout)
        
        try:
            element = wait.until(EC.presence_of_element_located(locator))
            logger.debug(f"Element found successfully: {locator}")
            return element
        except TimeoutException:
            logger.warning(f"Element not found within {timeout}s: {locator}")
            return None
        except StaleElementReferenceException:
            logger.warning(f"Stale element detected, retrying: {locator}")
            return self.find_element_safely(locator, timeout)
    
    def click_when_clickable(self, locator: Tuple[str, str], timeout: Optional[int] = None) -> bool:
        """Click element only when it's clickable with retry logic."""
        timeout = timeout or self.timeout
        wait = WebDriverWait(self.driver, timeout)
        
        try:
            element = wait.until(EC.element_to_be_clickable(locator))
            
            # Scroll element into view before clicking
            self.driver.execute_script("arguments[0].scrollIntoView(true);", element)
            
            # Use Actions for more reliable clicking
            self.actions.move_to_element(element).click().perform()
            logger.info(f"Successfully clicked element: {locator}")
            return True
        except TimeoutException:
            logger.error(f"Element not clickable: {locator}")
            return False
        except Exception as e:
            logger.error(f"Click failed for {locator}: {str(e)}")
            return False
    
    def enter_text_safely(self, locator: Tuple[str, str], text: str, 
                         clear_first: bool = True, validate: bool = True) -> bool:
        """Enter text with validation and error handling."""
        element = self.find_element_safely(locator)
        if not element:
            return False
        
        try:
            # Scroll to element and focus
            self.driver.execute_script("arguments[0].scrollIntoView(true);", element)
            element.click()  # Focus the element
            
            if clear_first:
                element.clear()
            
            element.send_keys(text)
            
            # Verify text was entered correctly if validation is enabled
            if validate:
                entered_value = element.get_attribute('value')
                if entered_value == text:
                    logger.info(f"Text entered successfully: '{text}' in {locator}")
                    return True
                else:
                    logger.warning(f"Text entry verification failed. Expected: '{text}', Got: '{entered_value}'")
                    return False
            
            logger.info(f"Text entered (no validation): '{text}' in {locator}")
            return True
                
        except Exception as e:
            logger.error(f"Failed to enter text in {locator}: {str(e)}")
            return False

Read the full file on GitHub · 215 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 215 lines · 1,767 tokens per session scan A 95a577555e07

Subscribe to this mod's changes

page-object-patterns is a cursor rule published in the GitHub repository tugkanboz/awesome-cursorrules (20 stars, last pushed 4d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,767 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.