Library provides the way to automatically manage drivers for different browsers
Project description
Webdriver Manager for Python
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.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.utils import ChromeType
driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).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:
# bash
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:
# python
import os
os.environ['GH_TOKEN'] = "asdasdasdasd"
WDM_LOG_LEVEL
To silent webdriver_manager
logs and remove them from console, initialize env variable WDM_LOG_LEVEL
with '0'
value before your selenium tests:
import os
os.environ['WDM_LOG_LEVEL'] = '0'
or via constructor:
ChromeDriverManager("2.26", log_level=0).install()
WDM_PRINT_FIRST_LINE
By default webdriver manager prints a blank space before its log output if logging is enabled. If you want to disable this, initialize WDM_PRINT_FIRST_LINE
with 'False'
before your tests:
import os
os.environ['WDM_PRINT_FIRST_LINE'] = 'False'
or via constructor:
ChromeDriverManager("2.26", print_first_line=False).install()
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'
version
Specify the version of webdriver you need. And webdriver-manager will download it from sources for your os.
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:
ChromeDriverManager("2.26", cache_valid_range=1).install()
This will make your test automation more elegant and robust!
Cheers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file webdriver_manager-3.5.3.tar.gz
.
File metadata
- Download URL: webdriver_manager-3.5.3.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33c86736c51839abdcdeed1bbfd1f0d55277411bae4f232fdc9ace0c518e04f4 |
|
MD5 | 7ec77b260b281f5def6c7a28c35b5641 |
|
BLAKE2b-256 | 5b4453f5b5e58c20a68cc66e7788867619648024b86fd20898e78aa82f5255f9 |
File details
Details for the file webdriver_manager-3.5.3-py2.py3-none-any.whl
.
File metadata
- Download URL: webdriver_manager-3.5.3-py2.py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef4320064bec22df5b2d7ea0509d08a99d3cecd1ddabd190f26f871dfa52a362 |
|
MD5 | bacd9b4bb22a925ca826402294d63360 |
|
BLAKE2b-256 | 3fca12b5e113b7078bf809bb556c3db55dd0db7ab6d43b51a81b57ec7bb99e44 |