selenium_drivers package

Submodules

selenium_drivers.base_driver_setup module

class selenium_drivers.base_driver_setup.BaseDriverSetup(additional_options: dict[str, str | None] | None = None, **kwargs)[source]

Bases: WebDriverSetup, ABC

Abstract base class for WebDriver setups. Provides common functionality for handling options and creating WebDriver instances.

abstract create_default_options() BaseOptions[source]

Create and return default options for the specific browser.

abstract create_webdriver_instance(service, options) WebDriver[source]

Create the WebDriver instance using the provided service and options.

get_driver(custom_options: BaseOptions | None = None) WebDriver[source]

Create and return a WebDriver instance with customizable options.

Parameters:
  • custom_options (BaseOptions, optional) – If provided, these options

  • class. (will override the default options set in the)

Returns:

An instance of the WebDriver with the specified options.

Return type:

RemoteWebDriver

Raises:

WebDriverException – If the WebDriver initialization fails.

abstract get_driver_service() None[source]

Return the WebDriver service for the specific browser.

setup_options(options: BaseOptions) None[source]

Set up options based on additional configuration. This method can be overridden for browser-specific options.

class selenium_drivers.base_driver_setup.ChromeDriverSetup(additional_options: dict[str, str | None] | None = None, **kwargs)[source]

Bases: BaseDriverSetup

create_default_options() Options[source]

Create and return default ChromeOptions.

create_webdriver_instance(service, options) WebDriver[source]

Create Chrome WebDriver instance.

get_driver_service() Service[source]

Return the WebDriver service for Chrome.

class selenium_drivers.base_driver_setup.EdgeDriverSetup(additional_options: dict[str, str | None] | None = None, **kwargs)[source]

Bases: BaseDriverSetup

create_default_options() Options[source]

Create and return default EdgeOptions.

create_webdriver_instance(service, options) WebDriver[source]

Create Edge WebDriver instance.

get_driver_service() Service[source]

Return the WebDriver service for Edge.

class selenium_drivers.base_driver_setup.FirefoxDriverSetup(additional_options: dict[str, str | None] | None = None, **kwargs)[source]

Bases: BaseDriverSetup

create_default_options() Options[source]

Create and return default FirefoxOptions.

create_webdriver_instance(service, options) WebDriver[source]

Create Firefox WebDriver instance.

get_driver_service() Service[source]

Return the WebDriver service for Firefox.

class selenium_drivers.base_driver_setup.IEDriverSetup(additional_options: dict[str, str | None] | None = None, **kwargs)[source]

Bases: BaseDriverSetup

create_default_options() Options[source]

Create and return default IEOptions.

create_webdriver_instance(service, options) WebDriver[source]

Create IE WebDriver instance.

get_driver_service() Service[source]

Return the WebDriver service for IE.

selenium_drivers.driver_factory module

selenium_drivers.driver_factory.get_driver(browser: str, **kwargs)[source]

Factory method to instantiate a web driver based on the browser type and custom options.

Parameters:
  • browser (str) – The type of browser (‘chrome’, ‘firefox’, ‘edge’, ‘ie’).

  • **kwargs – Additional options to pass to the driver setup (e.g., proxy, headless).

Returns:

An instance of a WebDriver for the specified browser.

Return type:

WebDriver

Raises:

ValueError – If the browser type is unsupported.

selenium_drivers.webdriver_setup module

class selenium_drivers.webdriver_setup.WebDriverSetup(proxy: str | None = None, headless: bool = True, sandbox: bool = True, disable_dev_shm_usage: bool = False, ignore_certificate_errors: bool = False, disable_gpu: bool = False, log_level: int = 3, disable_notifications: bool = False, disable_popup_blocking: bool = False, user_agent: str | None = None, window_size: str | None = None, incognito: bool = False, disable_extensions: bool = False, verbose: bool = False, disable_infobars: bool = False, start_fullscreen: bool = False, disable_save_password_bubble: bool = False, safebrowsing_disable_download_protection: bool = False, disable_browser_side_navigation: bool = False, no_proxy_server: bool = False)[source]

Bases: object

attempt_recovery_or_exit() None[source]

Attempt to recover from a WebDriver failure by reinitializing the driver.

If the recovery attempt fails, the function will log an error and exit.

handle_webdriver_error(action: Callable[[], Any], error: Exception, retries: int = 3, delay: int = 2, action_desc: str = 'operating the WebDriver') object[source]

Handles WebDriver errors and attempts to recover from them by retrying the failed action.

Parameters:
  • action (Callable) – The action to retry.

  • error (Exception) – The caught error during WebDriver operation.

  • retries (int) – Number of retry attempts (default is 3).

  • delay (int) – Delay between retries (default is 2 seconds).

  • action_desc (str) – Description of the action being attempted.

Returns:

The result of the retried action.

Return type:

Any

Raises:

Exception – If the retries fail, it raises the final exception.

setup_options(options: BaseOptions) None[source]

Configure WebDriver options based on initialized settings.

This method adds various options to the browser instance being used.

Parameters:

options (BaseOptions) – Browser-specific options to configure.

selenium_drivers.webdriver_setup.setup_logging(config_path: str = 'config/logging.ini', default_level: int = 20)[source]

Setup logging configuration from a specified path.

Arguments: config_path – string, path to the logging configuration file (default ‘config/logging.ini’) default_level – logging level, default to logging.INFO if configuration file is not found

Module contents