I get tired of having to rewrite the setup logic for selenium drivers in every project. Time to consolidate.
This will automatically handle any downloading of drivers or browsers via SeleniumManager
from setup_selenium import SetupSelenium
s = SetupSelenium(headless=True)
assert s.driver.service.is_connectable()
Advanced usage:
from setup_selenium import Browser, SetupSelenium
s = SetupSelenium(Browser.FIREFOX, headless=True, driver_version="118.0.5993.70")
s = SetupSelenium(Browser.CHROME, headless=True, driver_version="118.0.5993.70",
driver_path="/path/to/webdriver"
)
Note
Version and path arguments follow the logic of SeleniumManager. Caution is advised in cases where version and path do not match. See their documentation.
from setup_selenium import Browser, SetupSelenium
driver_path, browser_path = SetupSelenium.install_driver(Browser.CHROME, driver_version="118.0.5993.70")
from setup_selenium import Browser, SetupSelenium
driver = SetupSelenium.create_driver(browser=Browser.CHROME, headless=True)
Advanced usage:
from setup_selenium import Browser, SetupSelenium
driver = SetupSelenium.create_driver(
browser=Browser.CHROME,
headless=True,
enable_log_performance=False,
enable_log_console=False,
enable_log_driver=False,
log_dir="./logs",
binary="/usr/bin/chromium",
driver_path="/usr/bin/chromedriver",
)
Note
It is possible to enable the performance and console logging but only for chrome based browsers. This only enables the browser ability. It is up to the tester to handle logging the messages.
import logging
from setup_selenium import Browser, SetupSelenium, set_logger
set_logger(logging.getLogger("your_custom_logger"))
driver = SetupSelenium.create_driver(browser=Browser.CHROME, headless=True)
This package not only handles setup of the webdriver but also will automatically install the webdriver and/or browser depending on your configuration.
If you do not provide a driver_path
argument to create_driver
the package
will utilize selenium-manager
to install the webdriver for the browser type selected.
If the selenium-manager
cannot find the install path for the browser type
(which is usually in the native install path) it will download a version of the browser
and use that.
Passing a valid binary_path
will not trigger any download of the browser.
Passing a valid driver_path
will not trigger any download of the webdriver.
- removed
--remote-debugging-pipe
from default chrome options (causes older chrome to crash)
- official release