Selenium Documentation

repository·trunk·Indexed 23 days ago

https://github.com/seleniumhq/seleniumhq.github.io

Official source for Selenium documentation and site content. Covers core concepts such as HTTP-based browser communication, Selenium Grid, and features introduced in Selenium 4 including Relative Locators, NetworkInterceptor, and Chrome DevTools Protocol (CDP) support. Includes guides on contributing to the project, governance under the Software Freedom Conservancy, and technical implementation details for Java, Ruby, and TypeScript frameworks.

Tokens
178.3K
Snippets
373
Records
1.1K
Agent score
76%

What's inside Selenium

  1. What is Selenium?

    trunk

    Selenium is an umbrella project providing tools and libraries for web browser automation. It includes:

    • Extensions to emulate user interaction with browsers.
    • A distribution server for scaling browser allocation.
    • Infrastructure for implementing the W3C WebDriver specification, allowing you to write interchangeable code that runs across all major web browsers.

    The core component is WebDriver, an interface used to write instruction sets that can be executed interchangeably in different browsers.

  2. Overview of SeleniumBase

    trunk

    SeleniumBase is an all-in-one browser automation framework built on top of Selenium WebDriver Python bindings. It is designed for testing, web scraping, web crawling, and stealth purposes. It provides over 500 API methods and integrates deeply with pytest.

    Key features include:

    • Test recorder: Record and playback tests.
    • Stealth Mode: Bypasses Cloudflare and anti-bot measures using UC Mode (Ultra-Chrome Mode) and CDP Mode (Chrome DevTools Protocol Mode).
    • Advanced Reporting: Automatic generation of detailed reports including screenshots, stack traces, and interactive HTML dashboards.
    • Intelligent Waits: Built-in mechanisms to reduce test flakiness.
    • CI/CD Ready: Supports headless Linux environments via XVFB (e.g., in GitHub Actions).
  3. What is Selenium Manager and how to use it

    trunk

    Selenium Manager is the official driver manager for Selenium, implemented as a Rust-based CLI tool. It is shipped with every Selenium release (as of version 4.6) and is used by Selenium bindings by default to automate driver and browser management.

    Key Characteristics

    • Automatic Fallback: It is an opt-in feature for Selenium bindings. If you manually provide a driver (via PATH or system properties), Selenium Manager will not interfere. It only activates if no driver is found.
    • Cross-Platform: It works on Windows, Linux, and macOS.
    • Automated Management: It handles the discovery, downloading, and caching of both drivers and browsers.

    Automated Driver Management

    When a driver (e.g., chromedriver, geckodriver) is unavailable, Selenium Manager:

    1. Discovers the installed browser version on the machine.
    2. Resolves the matching driver version using vendor metadata.
    3. Downloads and uncompresses the driver.
    4. Caches the driver in ~/.cache/selenium for future use.
  4. Overview of Selenium design patterns and strategies

    trunk

    To manage large test suites and reduce maintenance overhead, several design patterns can be applied to WebDriver tests:

    • Domain-Driven Design: Express tests using the language of the end-user.
    • PageObjects: Create simple abstractions of the web application's UI.
    • LoadableComponent: Model PageObjects as components that handle their own loading logic.
    • Bot Style Tests: Use a command-based approach to automation instead of the object-based approach used by PageObjects.
  5. Overview of Selenium Grid

    trunk

    Selenium Grid is a tool designed to run WebDriver scripts on remote machines by routing commands from the client to remote browser instances. It is primarily used to:

    • Run tests in parallel across multiple machines to reduce execution time.
    • Test different browser versions by routing to specific environments.
    • Enable cross-platform testing by executing scripts on various operating systems.
  6. Overview of Selenium design strategies

    trunk

    To prevent test suites from becoming difficult to maintain as they grow, several design patterns are recommended for WebDriver automation:

    • Domain-Driven Design: Express tests using the language of the application's end-users.
    • PageObjects: Create simple abstractions of the Web application's UI.
    • LoadableComponent: Model PageObjects as components that ensure they are fully loaded before use.
    • BotStyleTests: Use a command-based approach (action-oriented abstractions) instead of the object-based PageObject approach.
  7. Basic commands for interacting with web elements

    trunk

    Selenium provides five basic commands for manipulating web elements. These commands emulate user behavior and include built-in validations such as scrolling elements into view and checking for interactability.

    Available Commands:

    • click: Applies to any element. Executes at the center of the element.
    • send keys: Applies to text fields and keyboard-interactable elements. Types provided keys into the element.
    • clear: Applies to text fields and content-editable elements. Resets the element's content.
    • submit: Applies only to form elements. (Note: In Selenium 4, this is implemented via script; it is recommended to use click on the submission button instead).
    • select: Used for selecting items from select lists.
  8. Internet Explorer support status and compatibility

    trunk

    As of June 2022, Selenium no longer supports standalone Internet Explorer. However, the Internet Explorer driver still supports running Microsoft Edge when it is in "IE Compatibility Mode."

    Important Recommendations:

    • The IE Driver is the only driver maintained directly by the Selenium Project.
    • While both 32-bit and 64-bit binaries are available, the 64-bit driver has known limitations. It is recommended to use the 32-bit driver for better stability.
  9. Basic element interaction commands in Selenium

    trunk

    Selenium provides 5 basic commands for manipulating web elements:

    • click: Applies to any element.
    • send keys: Applies to text fields and keyboard-interactable elements.
    • clear: Applies to text fields and content-editable elements.
    • submit: Applies only to form elements.
    • select: Used for select lists (see Select List Elements).
  10. Understand the core capabilities of Selenium

    trunk

    Selenium is a toolset for web browser automation designed to remotely control browser instances and emulate user interactions. It allows you to simulate common end-user activities, including:

    • Entering text into input fields
    • Selecting drop-down values
    • Checking boxes
    • Clicking links
    • Performing mouse movements
    • Executing arbitrary JavaScript

    While frequently used for front-end website testing, Selenium is fundamentally a browser user agent library that can be composed with other libraries to suit various automation purposes.