or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

action-chains.mdbrowser-configuration.mdelement-interaction.mdindex.mdwaits-conditions.mdwebdriver-classes.md
tile.json

tessl/pypi-selenium

Python bindings for Selenium WebDriver providing automated browser control for multiple browsers including Chrome, Firefox, Edge, Safari, and Internet Explorer

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/selenium@4.29.x

To install, run

npx @tessl/cli install tessl/pypi-selenium@4.29.0

index.mddocs/

Selenium WebDriver

Selenium WebDriver is the official Python bindings for Selenium, providing automated browser control and testing capabilities. It supports multiple browsers including Chrome, Firefox, Edge, Safari, and Internet Explorer, enabling cross-browser web application testing and automation.

Package Information

  • Package Name: selenium
  • Package Type: PyPI
  • Language: Python
  • Installation: pip install selenium

Core Imports

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

For browser-specific configuration:

from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.firefox.options import Options as FirefoxOptions

Basic Usage

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Create WebDriver instance
driver = webdriver.Chrome()

# Navigate to a page
driver.get("https://example.com")

# Find elements and interact
element = driver.find_element(By.ID, "search-box")
element.send_keys("selenium python")
element.submit()

# Use explicit waits
wait = WebDriverWait(driver, 10)
results = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "results")))

# Take screenshot
driver.save_screenshot("results.png")

# Clean up
driver.quit()

Architecture

Selenium WebDriver follows a modular architecture:

  • WebDriver Classes: Browser-specific drivers (Chrome, Firefox, Edge, Safari, IE, Remote)
  • Service Objects: Manage browser driver processes and configuration
  • Options Objects: Configure browser behavior, extensions, and capabilities
  • Support Modules: Utilities for waits, element selection, actions, and expected conditions
  • WebElement Interface: Represents and interacts with DOM elements
  • Exception Hierarchy: Comprehensive error handling for various failure scenarios

Capabilities

WebDriver Classes and Browser Control

Core WebDriver classes for controlling different browsers with navigation, window management, and page interaction capabilities.

class Chrome(ChromiumDriver):
    def __init__(self, options: Options = None, service: Service = None, keep_alive: bool = True) -> None: ...

class Firefox(WebDriver):
    def __init__(self, options: Options = None, service: Service = None, keep_alive: bool = True) -> None: ...

class Edge(ChromiumDriver):
    def __init__(self, options: Options = None, service: Service = None, keep_alive: bool = True) -> None: ...

class Safari(WebDriver):
    def __init__(self, options: Options = None, service: Service = None, keep_alive: bool = True) -> None: ...

class Remote(WebDriver):
    def __init__(self, command_executor: str = 'http://127.0.0.1:4444', desired_capabilities: dict = None) -> None: ...

WebDriver Classes

Element Location and Interaction

Methods for finding elements on the page and interacting with them through clicks, text input, and attribute access.

class WebDriver:
    def find_element(self, by: str, value: str) -> WebElement: ...
    def find_elements(self, by: str, value: str) -> list[WebElement]: ...
    def get(self, url: str) -> None: ...
    def current_url(self) -> str: ...
    def title(self) -> str: ...
    def page_source(self) -> str: ...
    def close(self) -> None: ...
    def quit(self) -> None: ...

class WebElement:
    def click(self) -> None: ...
    def send_keys(self, *value: str) -> None: ...
    def clear(self) -> None: ...
    def get_attribute(self, name: str) -> str | None: ...
    def is_displayed(self) -> bool: ...
    def is_enabled(self) -> bool: ...
    def is_selected(self) -> bool: ...

Element Location and Interaction

Action Chains and Complex Interactions

Advanced user interaction simulation including mouse movements, keyboard combinations, drag and drop operations.

class ActionChains:
    def __init__(self, driver: WebDriver, duration: int = 250) -> None: ...
    def click(self, on_element: WebElement = None) -> ActionChains: ...
    def click_and_hold(self, on_element: WebElement = None) -> ActionChains: ...
    def context_click(self, on_element: WebElement = None) -> ActionChains: ...
    def double_click(self, on_element: WebElement = None) -> ActionChains: ...
    def drag_and_drop(self, source: WebElement, target: WebElement) -> ActionChains: ...
    def move_to_element(self, to_element: WebElement) -> ActionChains: ...
    def send_keys(self, *keys_to_send: str) -> ActionChains: ...
    def perform(self) -> None: ...

Action Chains

Waits and Expected Conditions

Explicit and implicit wait mechanisms with pre-built conditions for synchronizing test execution with page state.

class WebDriverWait:
    def __init__(self, driver: WebDriver, timeout: float, poll_frequency: float = 0.5) -> None: ...
    def until(self, method: Callable, message: str = "") -> Any: ...
    def until_not(self, method: Callable, message: str = "") -> Any: ...

# Expected Conditions module functions
def title_is(title: str) -> Callable: ...
def presence_of_element_located(locator: tuple[str, str]) -> Callable: ...
def visibility_of_element_located(locator: tuple[str, str]) -> Callable: ...
def element_to_be_clickable(locator: tuple[str, str]) -> Callable: ...
def text_to_be_present_in_element(locator: tuple[str, str], text: str) -> Callable: ...

Waits and Expected Conditions

Browser Configuration and Options

Configuration options for customizing browser behavior, setting up proxies, and managing browser capabilities.

class Options:
    def add_argument(self, argument: str) -> None: ...
    def add_extension(self, extension: str) -> None: ...
    def add_experimental_option(self, name: str, value: Any) -> None: ...
    def set_capability(self, name: str, value: Any) -> None: ...

class Service:
    def __init__(self, executable_path: str = None, port: int = 0, service_args: list = None) -> None: ...
    def start(self) -> None: ...
    def stop(self) -> None: ...

class Proxy:
    def __init__(self) -> None: ...
    http_proxy: str
    ssl_proxy: str
    proxy_type: ProxyType

Browser Configuration