# Webdriver Manager for Python
This is a fork project based on [SergeyPirogov/webdriver_manager](https://github.com/SergeyPirogov/webdriver_manager),
which is using a daily refreshed mirror of all the driver
sites [HansBug/browser_drivers_mirror](https://huggingface.co/HansBug/browser_drivers_mirror). This means this package
can
be directly used in China mainland.
[![Tests](https://github.com/HansBug/hf_webdriver_manager/actions/workflows/test.yml/badge.svg)](https://github.com/HansBug/hf_webdriver_manager/actions/workflows/test.yml)
[![PyPI](https://img.shields.io/pypi/v/hf-webdriver-manager.svg)](https://pypi.org/project/hf-webdriver-manager)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/hf-webdriver-manager.svg)](https://pypi.org/project/hf-webdriver-manager/)
[![codecov](https://codecov.io/gh/HansBug/hf_webdriver_manager/branch/master/graph/badge.svg)](https://codecov.io/gh/HansBug/hf_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 hf-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()
```
## 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
### `DRIVER_SITE`
You can change the resource address of the Selenium browser driver by setting the `DRIVER_SITE` environment variable.
The default value is `https://huggingface.co/datasets/HansBug/browser_drivers_mirror/resolve/main`.
### `WDM_LOG`
Turn off hf-webdriver-manager logs use:
```python
import logging
import os
os.environ['WDM_LOG'] = str(logging.NOTSET)
```
### `WDM_PROGRESS_BAR`
Turn off the progress bar which is displayed on downloads:
```python
import os
os.environ['WDM_PROGRESS_BAR'] = str(0)
```
### `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 hf-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/HansBug/hf_webdriver_manager",
"name": "hf-webdriver-manager",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "testing,selenium,driver,test automation",
"author": "HansBug",
"author_email": "hansbug@buaa.edu.cn",
"download_url": "https://files.pythonhosted.org/packages/b0/96/89c7c3e2af0a84a2f00174e5796d1e912380f1f2701c8e0f77f57a63b28c/hf-webdriver-manager-0.2.0.tar.gz",
"platform": null,
"description": "# Webdriver Manager for Python\n\nThis is a fork project based on [SergeyPirogov/webdriver_manager](https://github.com/SergeyPirogov/webdriver_manager),\nwhich is using a daily refreshed mirror of all the driver\nsites [HansBug/browser_drivers_mirror](https://huggingface.co/HansBug/browser_drivers_mirror). This means this package\ncan\nbe directly used in China mainland.\n\n[![Tests](https://github.com/HansBug/hf_webdriver_manager/actions/workflows/test.yml/badge.svg)](https://github.com/HansBug/hf_webdriver_manager/actions/workflows/test.yml)\n[![PyPI](https://img.shields.io/pypi/v/hf-webdriver-manager.svg)](https://pypi.org/project/hf-webdriver-manager)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/hf-webdriver-manager.svg)](https://pypi.org/project/hf-webdriver-manager/)\n[![codecov](https://codecov.io/gh/HansBug/hf_webdriver_manager/branch/master/graph/badge.svg)](https://codecov.io/gh/HansBug/hf_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\n\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\nand again.\n\nWith webdriver manager, you just need to do two simple steps:\n\n#### Install manager:\n\n```bash\npip install hf-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\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#### 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\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\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\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#### 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\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\n\nversion = read_version_from_cmd(\"/usr/bin/firefox-bin --version\", PATTERN[\"firefox\"])\ndriver_binary = FirefoxDriverManager(version=version).install()\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### `DRIVER_SITE`\n\nYou can change the resource address of the Selenium browser driver by setting the `DRIVER_SITE` environment variable.\nThe default value is `https://huggingface.co/datasets/HansBug/browser_drivers_mirror/resolve/main`.\n\n### `WDM_LOG`\n\nTurn off hf-webdriver-manager logs use:\n\n```python\nimport logging\nimport os\n\nos.environ['WDM_LOG'] = str(logging.NOTSET)\n```\n\n### `WDM_PROGRESS_BAR`\n\nTurn off the progress bar which is displayed on downloads:\n\n```python\nimport os\n\nos.environ['WDM_PROGRESS_BAR'] = str(0)\n```\n\n### `WDM_LOCAL`\n\nBy default, all driver binaries are saved to user.home/.wdm folder. You can override this setting and save binaries to\nproject.root/.wdm.\n\n```python\nimport os\n\nos.environ['WDM_LOCAL'] = '1'\n```\n\n### `WDM_SSL_VERIFY`\n\nSSL verification can be disabled for downloading webdriver binaries in case when you have troubles with SSL Certificates\nor 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`\n\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`\n\nSpecify the version of webdriver you need. And hf-webdriver-manager will download it from sources for your os.\n\n```python\nfrom webdriver_manager.chrome import ChromeDriverManager\n\nChromeDriverManager(version=\"2.26\").install()\n```\n\n### `cache_valid_range`\n\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\n\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\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": "Apache License, Version 2.0",
"summary": "Library provides the way to automatically manage drivers for different browsers.",
"version": "0.2.0",
"project_urls": {
"Homepage": "https://github.com/HansBug/hf_webdriver_manager"
},
"split_keywords": [
"testing",
"selenium",
"driver",
"test automation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d5c8cc4bcf22c2a05316d5a291db3c7f2f03c5e9b9cd757de593752d6c076f04",
"md5": "25d61c47d6c4d5580f0ccc0735b0e0f7",
"sha256": "7773985a83d1eff3db233bb71f3b6f64851dc4b116c354120b0bcd687738b991"
},
"downloads": -1,
"filename": "hf_webdriver_manager-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "25d61c47d6c4d5580f0ccc0735b0e0f7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 27444,
"upload_time": "2023-05-08T12:33:44",
"upload_time_iso_8601": "2023-05-08T12:33:44.404635Z",
"url": "https://files.pythonhosted.org/packages/d5/c8/cc4bcf22c2a05316d5a291db3c7f2f03c5e9b9cd757de593752d6c076f04/hf_webdriver_manager-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b09689c7c3e2af0a84a2f00174e5796d1e912380f1f2701c8e0f77f57a63b28c",
"md5": "db7c5a7d240694adf89016896e131a2e",
"sha256": "affbca1d8ab10a9149f86b65dd58a299aa6a65ce6341518a927ced9cffed8c46"
},
"downloads": -1,
"filename": "hf-webdriver-manager-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "db7c5a7d240694adf89016896e131a2e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 22495,
"upload_time": "2023-05-08T12:33:47",
"upload_time_iso_8601": "2023-05-08T12:33:47.984257Z",
"url": "https://files.pythonhosted.org/packages/b0/96/89c7c3e2af0a84a2f00174e5796d1e912380f1f2701c8e0f77f57a63b28c/hf-webdriver-manager-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-08 12:33:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "HansBug",
"github_project": "hf_webdriver_manager",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "hf-webdriver-manager"
}