Skip to main content

Library provides the way to automatically manage drivers for different browsers

Project description

Webdriver Manager for Python

Tests PyPI Supported Python Versions codecov

Patreon

The main idea is to simplify management of binary drivers for different browsers.

For now support:

Compatible with Selenium 4.x and below.

Before: You should download binary chromedriver, unzip it somewhere in you PC and set path to this driver like this:

from selenium import webdriver
driver = webdriver.Chrome('/home/user/drivers/chromedriver')

It’s boring!!! Moreover every time the new version of driver released, you should go and repeat all steps again and again.

With webdriver manager, you just need to do two simple steps:

Install manager:

pip install webdriver-manager

Use with Chrome

# selenium 3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

Use with Chromium

# selenium 3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType

driver = webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType

driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))

Use with Brave

# selenium 3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType

driver = webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType

driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()))

Use with Firefox

# selenium 3
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))

Use with IE

# selenium 3
from selenium import webdriver
from webdriver_manager.microsoft import IEDriverManager

driver = webdriver.Ie(IEDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import IEDriverManager

driver = webdriver.Ie(service=Service(IEDriverManager().install()))

Use with Edge

# selenium 3
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(EdgeChromiumDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()))

Use with Opera

# selenium 3 & 4
from selenium import webdriver
from webdriver_manager.opera import OperaDriverManager

driver = webdriver.Opera(executable_path=OperaDriverManager().install())

If the Opera browser is installed in a location other than C:/Program Files or C:/Program Files (x86) on windows and /usr/bin/opera for all unix variants and mac, then use the below code,

from selenium import webdriver
from webdriver_manager.opera import OperaDriverManager

options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.binary_location = "C:\\Users\\USERNAME\\FOLDERLOCATION\\Opera\\VERSION\\opera.exe"
driver = webdriver.Opera(executable_path=OperaDriverManager().install(), options=options)

Configuration

webdriver_manager has several configuration variables you can be interested in.

GH_TOKEN

webdriver_manager downloading some webdrivers from their official GitHub repositories but GitHub has limitations like 60 requests per hour for unauthenticated users. In case not to face an error related to github credentials, you need to create github token and place it into your environment: (*)

Example:

export GH_TOKEN = "asdasdasdasd"

(*) access_token required to work with GitHub API more info.

There is also possibility to set same variable via ENV VARIABLES, example:

import os

os.environ['GH_TOKEN'] = "asdasdasdasd"

WDM_LOG

Turn off webdriver-manager logs use:

import logging

logging.getLogger('WDM').setLevel(logging.NOTSET)

WDM_LOCAL

By default all driver binaries are saved to user.home/.wdm folder. You can override this setting and save binaries to project.root/.wdm.

import os

os.environ['WDM_LOCAL'] = '1'

WDM_SSL_VERIFY

SSL verification can be disabled for downloading webdriver binaries in case when you have troubles with SSL Certificates or SSL Certificate Chain. Just set the environment variable WDM_SSL_VERIFY to "0".

import os

os.environ['WDM_SSL_VERIFY'] = '0'

path

Set the directory where you want to download and save the webdriver. You can use relative and absolute paths.

from webdriver_manager.chrome import ChromeDriverManager

ChromeDriverManager(path = r".\\Drivers").install()

version

Specify the version of webdriver you need. And webdriver-manager will download it from sources for your os.

from webdriver_manager.chrome import ChromeDriverManager

ChromeDriverManager(version="2.26").install()

cache_valid_range

Driver cache by default is valid for 1 day. You are able to change this value using constructor parameter:

from webdriver_manager.chrome import ChromeDriverManager

ChromeDriverManager("2.26", cache_valid_range=1).install()

Custom HTTP Client

If you need to add custom HTTP logic like session or proxy you can define your custom HttpClient implementation.

import os

import requests
from requests import Response

from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.download_manager import WDMDownloadManager
from webdriver_manager.core.http import HttpClient
from webdriver_manager.core.logger import log

class CustomHttpClient(HttpClient):

    def get(self, url, params=None, **kwargs) -> Response:
        """
        Add you own logic here like session or proxy etc.
        """
        log("The call will be done with custom HTTP client")
        return requests.get(url, params, **kwargs)


def test_can_get_chrome_driver_with_custom_http_client():
    http_client = CustomHttpClient()
    download_manager = WDMDownloadManager(http_client)
    path = ChromeDriverManager(download_manager=download_manager).install()
    assert os.path.exists(path)

This will make your test automation more elegant and robust!

Cheers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webdriver_manager-3.6.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

webdriver_manager-3.6.0-py2.py3-none-any.whl (23.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file webdriver_manager-3.6.0.tar.gz.

File metadata

  • Download URL: webdriver_manager-3.6.0.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for webdriver_manager-3.6.0.tar.gz
Algorithm Hash digest
SHA256 c10c9012a9e1957efacc4491bcc0b2de2f169adb6d41c7786dbc3d7d803c714c
MD5 d316cc0ec9321fda169c5e3f0344c422
BLAKE2b-256 c92ba27fb219ee06de1779f281fabf9a636fbaf6814765fbea87f053ee1d15af

See more details on using hashes here.

File details

Details for the file webdriver_manager-3.6.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for webdriver_manager-3.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 de8f911c18f0ecf4aacfef508a286a536c11fc9827d112328e73ce3f9ec4beec
MD5 79dd5b699e5774327ed3b9df19265fff
BLAKE2b-256 c319f0e45fce2a405e6f91ace45a21b535030fa897f952475c8543685fa7bee6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page