# Webdriver Manager for Python
[![Tests](https://github.com/SergeyPirogov/webdriver_manager/actions/workflows/test.yml/badge.svg)](https://github.com/SergeyPirogov/webdriver_manager/actions/workflows/test.yml)
[![PyPI](https://img.shields.io/pypi/v/webdriver_manager.svg)](https://pypi.org/project/webdriver-manager)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/webdriver_manager.svg)](https://pypi.org/project/webdriver-manager/)
[![codecov](https://codecov.io/gh/SergeyPirogov/webdriver_manager/branch/master/graph/badge.svg)](https://codecov.io/gh/SergeyPirogov/webdriver_manager)
## Support the library on [Patreon](https://www.patreon.com/automation_remarks)
The main idea is to simplify management of binary drivers for different browsers.
For now support:
- [ChromeDriver](#use-with-chrome)
- [EdgeChromiumDriver](#use-with-edge)
- [GeckoDriver](#use-with-firefox)
- [IEDriver](#use-with-ie)
- [OperaDriver](#use-with-opera)
Compatible with Selenium 4.x and below.
Before:
You need to download the chromedriver binary, unzip it somewhere on your PC and set the path to this driver like this:
```python
from selenium import webdriver
driver = webdriver.Chrome('/home/user/drivers/chromedriver')
```
It’s boring!!! Moreover, every time a new version of the driver is released, you need to repeat all these steps again and again.
With webdriver manager, you just need to do two simple steps:
#### Install manager:
```bash
pip install webdriver-manager
```
#### Use with Chrome
```python
# selenium 3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
```
#### Use with Chromium
```python
# 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())
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromiumService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
driver = webdriver.Chrome(service=ChromiumService(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))
```
#### Use with Brave
```python
# 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())
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as BraveService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
driver = webdriver.Chrome(service=BraveService(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()))
```
#### Use with Edge
```python
# selenium 3
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager().install())
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
```
#### Use with Firefox
```python
# selenium 3
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
```
#### Use with IE
```python
# selenium 3
from selenium import webdriver
from webdriver_manager.microsoft import IEDriverManager
driver = webdriver.Ie(IEDriverManager().install())
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.ie.service import Service as IEService
from webdriver_manager.microsoft import IEDriverManager
driver = webdriver.Ie(service=IEService(IEDriverManager().install()))
```
#### Use with Opera
```python
# selenium 3
from selenium import webdriver
from selenium.webdriver.chrome import service
from webdriver_manager.opera import OperaDriverManager
webdriver_service = service.Service(OperaDriverManager().install())
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
```
```python
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome import service
from webdriver_manager.opera import OperaDriverManager
webdriver_service = service.Service(OperaDriverManager().install())
webdriver_service.start()
options = webdriver.ChromeOptions()
options.add_experimental_option('w3c', True)
driver = webdriver.Remote(webdriver_service.service_url, options=options)
```
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,
```python
options = webdriver.ChromeOptions()
options.binary_location = "path/to/opera.exe"
driver = webdriver.Remote(webdriver_service.service_url, options=options)
```
#### Get browser version from path
To get the version of the browser from the executable of the browser itself:
```python
from webdriver_manager.core.utils import read_version_from_cmd, PATTERN
version = read_version_from_cmd("/usr/bin/firefox-bin --version", PATTERN["firefox"])
driver_binary = FirefoxDriverManager(version=version).install()
```
#### Custom Cache and File manager
```python
cache_manager = DriverCacheManager(file_manager=FileManager())
manager = ChromeDriverManager(cache_manager=cache_manager)
```
## Configuration
**webdriver_manager** has several configuration variables you can be interested in.
Any variable can be set using either .env file or via python directly
### `GH_TOKEN`
**webdriver_manager** downloading some webdrivers from their official GitHub repositories but GitHub has [limitations](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting) like 60 requests per hour for unauthenticated users.
In case not to face an error related to github credentials, you need to [create](https://help.github.com/articles/creating-an-access-token-for-command-line-use) github token and place it into your environment: (\*)
Example:
```bash
export GH_TOKEN = "asdasdasdasd"
```
(\*) access_token required to work with GitHub API [more info](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).
There is also possibility to set same variable via ENV VARIABLES, example:
```python
import os
os.environ['GH_TOKEN'] = "asdasdasdasd"
```
### `WDM_LOG`
Turn off webdriver-manager logs use:
```python
import logging
import os
os.environ['WDM_LOG'] = str(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.
```python
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"`.
```python
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.
```python
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.
```python
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:
```python
from webdriver_manager.chrome import ChromeDriverManager
ChromeDriverManager("2.26", cache_valid_range=1).install()
```
---
### Custom Logger
If you need to use a custom logger, you can create a logger and set it with `set_logger()`.
```python
import logging
from webdriver_manager.core.logger import set_logger
logger = logging.getLogger("custom_logger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
logger.addHandler(logging.FileHandler("custom.log"))
set_logger(logger)
```
---
### Custom HTTP Client
If you need to add custom HTTP logic like session or proxy you can define your custom HttpClient implementation.
```python
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
Raw data
{
"_id": null,
"home_page": "https://github.com/SergeyPirogov/webdriver_manager",
"name": "webdriver-manager-temp",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "testing,selenium,driver,test automation",
"author": "Sergey Pirogov",
"author_email": "automationremarks@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/56/a8/7969d4e83266b8631b5f900ddcf4761017d1140ee723b570c76ff1a1eeb6/webdriver_manager_temp-4.0.0.1.tar.gz",
"platform": null,
"description": "# Webdriver Manager for Python\n\n[![Tests](https://github.com/SergeyPirogov/webdriver_manager/actions/workflows/test.yml/badge.svg)](https://github.com/SergeyPirogov/webdriver_manager/actions/workflows/test.yml)\n[![PyPI](https://img.shields.io/pypi/v/webdriver_manager.svg)](https://pypi.org/project/webdriver-manager)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/webdriver_manager.svg)](https://pypi.org/project/webdriver-manager/)\n[![codecov](https://codecov.io/gh/SergeyPirogov/webdriver_manager/branch/master/graph/badge.svg)](https://codecov.io/gh/SergeyPirogov/webdriver_manager)\n\n## Support the library on [Patreon](https://www.patreon.com/automation_remarks)\n\nThe main idea is to simplify management of binary drivers for different browsers.\n\nFor now support:\n\n- [ChromeDriver](#use-with-chrome)\n- [EdgeChromiumDriver](#use-with-edge)\n- [GeckoDriver](#use-with-firefox)\n- [IEDriver](#use-with-ie)\n- [OperaDriver](#use-with-opera)\n\nCompatible with Selenium 4.x and below.\n\nBefore:\nYou need to download the chromedriver binary, unzip it somewhere on your PC and set the path to this driver like this:\n\n```python\nfrom selenium import webdriver\ndriver = webdriver.Chrome('/home/user/drivers/chromedriver')\n```\n\nIt\u2019s boring!!! Moreover, every time a new version of the driver is released, you need to repeat all these steps again and again.\n\nWith webdriver manager, you just need to do two simple steps:\n\n#### Install manager:\n\n```bash\npip install webdriver-manager\n```\n\n#### Use with Chrome\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom webdriver_manager.chrome import ChromeDriverManager\n\ndriver = webdriver.Chrome(ChromeDriverManager().install())\n```\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.service import Service as ChromeService\nfrom webdriver_manager.chrome import ChromeDriverManager\n\ndriver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))\n```\n\n#### Use with Chromium\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom webdriver_manager.core.utils import ChromeType\n\ndriver = webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())\n```\n\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.service import Service as ChromiumService\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom webdriver_manager.core.utils import ChromeType\n\ndriver = webdriver.Chrome(service=ChromiumService(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))\n```\n\n#### Use with Brave\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom webdriver_manager.core.utils import ChromeType\n\ndriver = webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install())\n```\n\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.service import Service as BraveService\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom webdriver_manager.core.utils import ChromeType\n\ndriver = webdriver.Chrome(service=BraveService(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()))\n```\n\n\n#### Use with Edge\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom webdriver_manager.microsoft import EdgeChromiumDriverManager\n\ndriver = webdriver.Edge(EdgeChromiumDriverManager().install())\n```\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.edge.service import Service as EdgeService\nfrom webdriver_manager.microsoft import EdgeChromiumDriverManager\n\ndriver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))\n```\n\n#### Use with Firefox\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom webdriver_manager.firefox import GeckoDriverManager\n\ndriver = webdriver.Firefox(executable_path=GeckoDriverManager().install())\n```\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.firefox.service import Service as FirefoxService\nfrom webdriver_manager.firefox import GeckoDriverManager\n\ndriver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))\n```\n\n#### Use with IE\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom webdriver_manager.microsoft import IEDriverManager\n\ndriver = webdriver.Ie(IEDriverManager().install())\n```\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.ie.service import Service as IEService\nfrom webdriver_manager.microsoft import IEDriverManager\n\ndriver = webdriver.Ie(service=IEService(IEDriverManager().install()))\n```\n\n\n#### Use with Opera\n\n```python\n# selenium 3\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome import service\nfrom webdriver_manager.opera import OperaDriverManager\n\nwebdriver_service = service.Service(OperaDriverManager().install())\nwebdriver_service.start()\n\ndriver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)\n```\n```python\n# selenium 4\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome import service\nfrom webdriver_manager.opera import OperaDriverManager\n\nwebdriver_service = service.Service(OperaDriverManager().install())\nwebdriver_service.start()\n\noptions = webdriver.ChromeOptions()\noptions.add_experimental_option('w3c', True)\n\ndriver = webdriver.Remote(webdriver_service.service_url, options=options)\n```\n\nIf the Opera browser is installed in a location other than `C:/Program Files` or `C:/Program Files (x86)` on windows\nand `/usr/bin/opera` for all unix variants and mac, then use the below code,\n\n```python\noptions = webdriver.ChromeOptions()\noptions.binary_location = \"path/to/opera.exe\"\ndriver = webdriver.Remote(webdriver_service.service_url, options=options)\n```\n\n#### Get browser version from path\n\nTo get the version of the browser from the executable of the browser itself:\n\n```python\nfrom webdriver_manager.core.utils import read_version_from_cmd, PATTERN\nversion = read_version_from_cmd(\"/usr/bin/firefox-bin --version\", PATTERN[\"firefox\"])\ndriver_binary = FirefoxDriverManager(version=version).install()\n```\n\n#### Custom Cache and File manager\n\n```python\ncache_manager = DriverCacheManager(file_manager=FileManager())\nmanager = ChromeDriverManager(cache_manager=cache_manager)\n```\n\n## Configuration\n\n**webdriver_manager** has several configuration variables you can be interested in.\nAny variable can be set using either .env file or via python directly\n\n### `GH_TOKEN`\n**webdriver_manager** downloading some webdrivers from their official GitHub repositories but GitHub has [limitations](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting) like 60 requests per hour for unauthenticated users.\nIn case not to face an error related to github credentials, you need to [create](https://help.github.com/articles/creating-an-access-token-for-command-line-use) github token and place it into your environment: (\\*)\n\nExample:\n\n```bash\nexport GH_TOKEN = \"asdasdasdasd\"\n```\n\n(\\*) access_token required to work with GitHub API [more info](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).\n\nThere is also possibility to set same variable via ENV VARIABLES, example:\n\n```python\nimport os\n\nos.environ['GH_TOKEN'] = \"asdasdasdasd\"\n```\n\n### `WDM_LOG`\nTurn off webdriver-manager logs use:\n\n```python\nimport logging\nimport os\n\nos.environ['WDM_LOG'] = str(logging.NOTSET)\n```\n\n### `WDM_LOCAL`\nBy default, all driver binaries are saved to user.home/.wdm folder. You can override this setting and save binaries to project.root/.wdm.\n\n```python\nimport os\n\nos.environ['WDM_LOCAL'] = '1'\n```\n\n### `WDM_SSL_VERIFY`\nSSL 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\"`.\n\n```python\nimport os\n\nos.environ['WDM_SSL_VERIFY'] = '0'\n```\n\n### `path`\nSet the directory where you want to download and save the webdriver. You can use relative and absolute paths.\n\n```python\nfrom webdriver_manager.chrome import ChromeDriverManager\n\nChromeDriverManager(path = r\".\\\\Drivers\").install()\n```\n\n### `version`\nSpecify the version of webdriver you need. And webdriver-manager will download it from sources for your os.\n```python\nfrom webdriver_manager.chrome import ChromeDriverManager\n\nChromeDriverManager(version=\"2.26\").install()\n```\n\n### `cache_valid_range`\nDriver cache by default is valid for 1 day. You are able to change this value using constructor parameter:\n\n```python\nfrom webdriver_manager.chrome import ChromeDriverManager\n\nChromeDriverManager(\"2.26\", cache_valid_range=1).install()\n```\n\n---\n\n### Custom Logger\n\nIf you need to use a custom logger, you can create a logger and set it with `set_logger()`.\n\n```python\nimport logging\nfrom webdriver_manager.core.logger import set_logger\n\nlogger = logging.getLogger(\"custom_logger\")\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\nlogger.addHandler(logging.FileHandler(\"custom.log\"))\n\nset_logger(logger)\n```\n\n---\n\n### Custom HTTP Client\nIf you need to add custom HTTP logic like session or proxy you can define your custom HttpClient implementation.\n\n```python\nimport os\n\nimport requests\nfrom requests import Response\n\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom webdriver_manager.core.download_manager import WDMDownloadManager\nfrom webdriver_manager.core.http import HttpClient\nfrom webdriver_manager.core.logger import log\n\nclass CustomHttpClient(HttpClient):\n\n def get(self, url, params=None, **kwargs) -> Response:\n \"\"\"\n Add you own logic here like session or proxy etc.\n \"\"\"\n log(\"The call will be done with custom HTTP client\")\n return requests.get(url, params, **kwargs)\n\n\ndef test_can_get_chrome_driver_with_custom_http_client():\n http_client = CustomHttpClient()\n download_manager = WDMDownloadManager(http_client)\n path = ChromeDriverManager(download_manager=download_manager).install()\n assert os.path.exists(path)\n```\n\n---\n\nThis will make your test automation more elegant and robust!\n\nCheers\n",
"bugtrack_url": null,
"license": "",
"summary": "Library provides the way to automatically manage drivers for different browsers",
"version": "4.0.0.1",
"project_urls": {
"Homepage": "https://github.com/SergeyPirogov/webdriver_manager"
},
"split_keywords": [
"testing",
"selenium",
"driver",
"test automation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "56a87969d4e83266b8631b5f900ddcf4761017d1140ee723b570c76ff1a1eeb6",
"md5": "ab65ac7a28a17c2ae70254e6ad1930a9",
"sha256": "b1e029b2403a87de4e0cb8c81cb7b7a3d6ed947c44b9a4954619847bdabdd41a"
},
"downloads": -1,
"filename": "webdriver_manager_temp-4.0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "ab65ac7a28a17c2ae70254e6ad1930a9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 22536,
"upload_time": "2023-08-29T08:30:33",
"upload_time_iso_8601": "2023-08-29T08:30:33.409398Z",
"url": "https://files.pythonhosted.org/packages/56/a8/7969d4e83266b8631b5f900ddcf4761017d1140ee723b570c76ff1a1eeb6/webdriver_manager_temp-4.0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-29 08:30:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SergeyPirogov",
"github_project": "webdriver_manager",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "webdriver-manager-temp"
}