Note that this package uses a pinned dependency for urllib3 and should be installed in an isolated environment.
python -m pip install open-webdriver
import os
from open_webdriver import open_webdriver
# Needed or else exceptions will be thrown when executed from github actions.
IS_HEADLESS = os.environ.get("GITHUB_ACTIONS") == "true"
def main():
with open_webdriver(headless=IS_HEADLESS) as driver:
driver.set_window_size(1440, 900) # Needed for headless mode.
# All Chromium / web driver dependencies are now installed.
driver.get("https://www.google.com")
assert driver.title == "Google"
if __name__ == "__main__":
main()
Mac/Windows/Linux all use chromium version 101.0.4951.41 The user agent string will always indicate a Windows client, unless overriden.
Yet another selenium webdriver wrapper API in python, with the aims of being the easist to use with only two lines of code to get running.
Unlike other selenium web driver wrappers, this one has tests for Windows10/MacOS/Ubuntu platforms.
One function is provided, open_webdriver(...)
which takes care of downloading, installing and then running selenium.
Additionally, sane defaults are set, such as headless by default and ssl certs turned off. This code is also tested and examples are provided for use with the nuitka cross compiler, which allows you to create an binary executable. This is great for distributing a compiled binary for Windows/MacOS/Ubuntu of your selenium bot with all original source code removed, making it impossible to reverse engineer.
open-webdriver
is built on top of webdriver-manager https://pypi.org/project/webdriver-manager/ library, but with the following changes/fixes:
os.environ['WDM_SSL_VERIFY'] = '0'
And other sensible platform specific fixes are applied in order for the selenium driver stack to pass the test suite.
Additionally, a versioned chromium binary is downloaded for Linux & Windows, while whatever Chrome system is used for Mac, due to app signing requirements.
When your app is launched, there will be a side folder name .wdm
which contain the download of the webdriver used and brawser used. The disk cache for the driver is set for 7 day, after which it will be checked for a new version.
Benefits:
Downsides:
Just simply run tox
at the command line and everything should be tested. You may need to install tox
with python -m pip tox
.
Run open_webdriver_test
for package tests. This is useful if you are on a server and want to figure out if open_webdriver will be able to be run in
headless mode using the chrome
driver.
Please see Dockerfile
for requirements for including open_webdriver
in your Docker app.
Docker is supported in this build. Please see the Dockerfile
and docker-compose.yml
for bringup instructions. Simply use docker-compose up
and then ssh into the docker instance and run open_webdriver_test
and verify that the test completes normally.
This package supports the Nuitka cross compiler to binary app. However to make this work YOU MUST include the package data for selenium or you will get errors about missing javascript files when the program loads. To get around this you'll need to add package data:
python -m nuitka --include-package-data=selenium ...
For example see the example build file: https://github.com/zackees/open-webdriver/blob/main/open_webdriver/tests/nuitka/test_binary_build.py
Pull requests are welcome for this code base. When you submit your pull request you will need to have the following:
tox
(also run on your pull request).Driver
returned from open_webdriver
is now of WebDriver type instead of one of the base classes. Should help linting.open_webdriver_test
cmdopen_webdriver_test
cmd