Selenium - Python - Quick Tips #1

03/17/2021, Wed
Categories: #testing #python
Tags: #selenium

Webdriver Manager

Use the latest version of the web driver for your browser of choice when testing by installing the webdriver_manager package.

pip install webdriver-manager

The package will automatically download the newest version when tests are run with Selenium. This will relieve you of having to manually download the driver for inclusion in a folder while testing.

Use it as follows

from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())

Explicit Wait with Lambda

When implicit waits are not enough to detect when an element is present on the screen, the use of the explicit wait with Python's lambda function will provide a better approach to discerning whether an element is present on the page.

element = WebDriverWait(driver, 20).until(
    lambda d: d.execute_script("return document.querySelector('#my_id');"))