CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-selenium

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

Pending
Overview
Eval results
Files

webdriver-classes.mddocs/

WebDriver Classes

This document covers the WebDriver classes for different browsers in Python Selenium WebDriver. Each browser-specific WebDriver inherits from the remote WebDriver and provides browser-specific functionality.

Base WebDriver Class

{ .api }

from selenium.webdriver.remote.webdriver import WebDriver

class WebDriver:
    def __init__(
        self,
        command_executor: Union[str, RemoteConnection] = 'http://127.0.0.1:4444/wd/hub',
        desired_capabilities: Optional[dict] = None,
        browser_profile: Optional[BaseOptions] = None,
        proxy: Optional[Proxy] = None,
        keep_alive: bool = False,
        file_detector: Optional[FileDetector] = None,
        options: Optional[BaseOptions] = None,
        service: Optional[Service] = None,
        strict_file_interactability: bool = True
    ) -> None

Description: The base WebDriver class for remote browser automation.

Parameters:

  • command_executor: URL of the WebDriver server or RemoteConnection instance
  • desired_capabilities: Dictionary of browser capabilities (deprecated)
  • browser_profile: Browser profile (deprecated, use options instead)
  • proxy: Proxy configuration
  • keep_alive: Whether to keep HTTP connection alive
  • file_detector: File detector for handling file uploads
  • options: Browser options object
  • service: Service object for local drivers
  • strict_file_interactability: Whether to enforce strict file interaction

Example:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# Remote WebDriver
driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    options=webdriver.ChromeOptions()
)

Chrome WebDriver

{ .api }

from selenium.webdriver.chrome.webdriver import WebDriver as Chrome

class WebDriver(ChromiumDriver):
    def __init__(
        self,
        options: Optional[ChromeOptions] = None,
        service: Optional[ChromeService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the ChromeDriver and allows you to drive the Chrome browser.

Parameters:

  • options: Instance of ChromeOptions for browser configuration
  • service: Service object for handling the ChromeDriver process
  • keep_alive: Whether to configure ChromeRemoteConnection to use HTTP keep-alive

Example:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

options = Options()
options.add_argument('--headless')
service = Service('/path/to/chromedriver')

driver = webdriver.Chrome(options=options, service=service)

Firefox WebDriver

{ .api }

from selenium.webdriver.firefox.webdriver import WebDriver as Firefox

class WebDriver(RemoteWebDriver):
    CONTEXT_CHROME = "chrome"
    CONTEXT_CONTENT = "content"
    
    def __init__(
        self,
        options: Optional[FirefoxOptions] = None,
        service: Optional[FirefoxService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the GeckoDriver and allows you to drive the Firefox browser.

Parameters:

  • options: Instance of FirefoxOptions for browser configuration
  • service: Service instance for managing the GeckoDriver process
  • keep_alive: Whether to configure RemoteConnection to use HTTP keep-alive

Firefox-Specific Methods:

{ .api }

def set_context(self, context: str) -> None

Description: Sets the context that Selenium commands are running in.

Parameters:

  • context: Either CONTEXT_CHROME or CONTEXT_CONTENT

{ .api }

@contextmanager
def context(self, context: str)

Description: Context manager for temporarily switching context.

Parameters:

  • context: Either CONTEXT_CHROME or CONTEXT_CONTENT

{ .api }

def install_addon(self, path: str, temporary: bool = False) -> str

Description: Installs Firefox addon.

Parameters:

  • path: Absolute path to the addon that will be installed
  • temporary: Whether to load the extension temporarily during the session

Returns: Identifier of installed addon

{ .api }

def uninstall_addon(self, identifier: str) -> None

Description: Uninstalls Firefox addon using its identifier.

Parameters:

  • identifier: The addon identifier returned by install_addon()

{ .api }

def get_full_page_screenshot_as_file(self, filename: str) -> bool

Description: Saves a full document screenshot to a PNG file.

Parameters:

  • filename: The full path where to save the screenshot (should end with .png)

Returns: True if successful, False otherwise

{ .api }

def get_full_page_screenshot_as_png(self) -> bytes

Description: Gets the full document screenshot as binary data.

Returns: PNG screenshot data as bytes

{ .api }

def get_full_page_screenshot_as_base64(self) -> str

Description: Gets the full document screenshot as a base64 encoded string.

Returns: Base64 encoded PNG screenshot

Example:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

# Firefox-specific features
with driver.context(driver.CONTEXT_CHROME):
    # Chrome context operations
    pass

addon_id = driver.install_addon('/path/to/addon.xpi')
driver.uninstall_addon(addon_id)

Edge WebDriver

{ .api }

from selenium.webdriver.edge.webdriver import WebDriver as Edge

class WebDriver(ChromiumDriver):
    def __init__(
        self,
        options: Optional[EdgeOptions] = None,
        service: Optional[EdgeService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the EdgeDriver and allows you to drive the Microsoft Edge browser.

Parameters:

  • options: Instance of EdgeOptions for browser configuration
  • service: Service object for handling the EdgeDriver process
  • keep_alive: Whether to configure EdgeRemoteConnection to use HTTP keep-alive

Example:

from selenium import webdriver
from selenium.webdriver.edge.options import Options

options = Options()
options.add_argument('--disable-extensions')
driver = webdriver.Edge(options=options)

Safari WebDriver

{ .api }

from selenium.webdriver.safari.webdriver import WebDriver as Safari

class WebDriver(RemoteWebDriver):
    def __init__(
        self,
        options: Optional[SafariOptions] = None,
        service: Optional[SafariService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the SafariDriver and allows you to drive the Safari browser.

Parameters:

  • options: Instance of SafariOptions for browser configuration
  • service: Service instance for managing the SafariDriver process
  • keep_alive: Whether to configure SafariRemoteConnection to use HTTP keep-alive

Example:

from selenium import webdriver

driver = webdriver.Safari()

Internet Explorer WebDriver

{ .api }

from selenium.webdriver.ie.webdriver import WebDriver as InternetExplorer

class WebDriver(RemoteWebDriver):
    def __init__(
        self,
        options: Optional[IeOptions] = None,
        service: Optional[IeService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the IEDriver and allows you to drive Internet Explorer.

Parameters:

  • options: Instance of IeOptions for browser configuration
  • service: Service instance for managing the IEDriver process
  • keep_alive: Whether to configure IeRemoteConnection to use HTTP keep-alive

Example:

from selenium import webdriver
from selenium.webdriver.ie.options import Options

options = Options()
options.ignore_protected_mode_settings = True
driver = webdriver.Ie(options=options)

WebKitGTK WebDriver

{ .api }

from selenium.webdriver.webkitgtk.webdriver import WebDriver as WebKitGTK

class WebDriver(RemoteWebDriver):
    def __init__(
        self,
        options: Optional[WebKitGTKOptions] = None,
        service: Optional[WebKitGTKService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the WebKitGTKDriver for GTK-based WebKit browsers.

Parameters:

  • options: Instance of WebKitGTKOptions for browser configuration
  • service: Service instance for managing the WebKitGTKDriver process
  • keep_alive: Whether to configure RemoteConnection to use HTTP keep-alive

WPEWebKit WebDriver

{ .api }

from selenium.webdriver.wpewebkit.webdriver import WebDriver as WPEWebKit

class WebDriver(RemoteWebDriver):
    def __init__(
        self,
        options: Optional[WPEWebKitOptions] = None,
        service: Optional[WPEWebKitService] = None,
        keep_alive: bool = True,
    ) -> None

Description: Controls the WPEWebKitDriver for WPE WebKit browsers.

Parameters:

  • options: Instance of WPEWebKitOptions for browser configuration
  • service: Service instance for managing the WPEWebKitDriver process
  • keep_alive: Whether to configure RemoteConnection to use HTTP keep-alive

Common WebDriver Methods

All WebDriver classes inherit common methods from the base RemoteWebDriver:

{ .api }

def get(self, url: str) -> None

Description: Loads a web page in the current browser session.

Parameters:

  • url: URL to load

{ .api }

def quit(self) -> None

Description: Quits the driver and closes every associated window.

{ .api }

def close(self) -> None

Description: Closes the current window.

{ .api }

def refresh(self) -> None

Description: Refreshes the current page.

{ .api }

def back(self) -> None

Description: Goes one step backward in the browser history.

{ .api }

def forward(self) -> None

Description: Goes one step forward in the browser history.

Example:

# Universal pattern for any browser
from selenium import webdriver

# Choose your browser
driver = webdriver.Chrome()  # or Firefox(), Edge(), Safari(), etc.

try:
    driver.get('https://example.com')
    driver.refresh()
    driver.back()
    driver.forward()
finally:
    driver.quit()

Browser Selection Best Practices

  1. Chrome: Most commonly used, excellent DevTools support
  2. Firefox: Good for cross-browser testing, supports full-page screenshots
  3. Edge: Windows integration, Chromium-based
  4. Safari: Required for macOS/iOS compatibility testing
  5. Remote: For distributed testing, cloud services, or containerized environments

Example of browser selection:

import os
from selenium import webdriver

def get_driver(browser_name: str):
    """Factory function to get the appropriate WebDriver"""
    browser_name = browser_name.lower()
    
    if browser_name == 'chrome':
        return webdriver.Chrome()
    elif browser_name == 'firefox':
        return webdriver.Firefox()
    elif browser_name == 'edge':
        return webdriver.Edge()
    elif browser_name == 'safari':
        return webdriver.Safari()
    else:
        raise ValueError(f"Unsupported browser: {browser_name}")

# Use environment variable or config
browser = os.getenv('BROWSER', 'chrome')
driver = get_driver(browser)

Install with Tessl CLI

npx tessl i tessl/pypi-selenium

docs

action-chains.md

browser-configuration.md

element-interaction.md

index.md

waits-conditions.md

webdriver-classes.md

tile.json