Registry /
testing / lambdatest-selenium-driver
Install & Compatibility
Where this runs
tested against v1.0.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 1.062s · 54.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.0s · import 0.974s · 55MB
54MB installed
● package 54MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
smartui_snapshot
✓ from lambdatest_selenium_driver import smartui_snapshot
webdriver.Remote
✓ from selenium import webdriver
Used for connecting to the LambdaTest remote Selenium grid.
Options
✓ from selenium.webdriver.chrome.options import Options as ChromeOptions
Or `FirefoxOptions`, etc., for browser-specific capabilities.
This quickstart demonstrates how to use `lambdatest-selenium-driver` with a remote Selenium WebDriver connected to the LambdaTest grid, including SmartUI snapshot capabilities. Ensure `LT_USERNAME`, `LT_ACCESS_KEY`, and optionally `PROJECT_TOKEN` (for SmartUI) environment variables are set. The `smartui_snapshot` function captures visual snapshots for comparison.
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.by import By
from lambdatest_selenium_driver import smartui_snapshot
LT_USERNAME = os.environ.get('LT_USERNAME', '')
LT_ACCESS_KEY = os.environ.get('LT_ACCESS_KEY', '')
if not LT_USERNAME or not LT_ACCESS_KEY:
print("Please set LT_USERNAME and LT_ACCESS_KEY environment variables.")
exit(1)
def run_lambdatest_smartui_test():
options = ChromeOptions()
options.browser_version = "latest"
options.platform_name = "Windows 10"
lt_options = {
"username": LT_USERNAME,
"accessKey": LT_ACCESS_KEY,
"build": "Python SmartUI Build",
"project": "My SmartUI Project",
"name": "SmartUI Sample Test",
"w3c": True,
"plugin": "python-python",
"smartUI.project": os.environ.get('PROJECT_TOKEN', 'Your_SmartUI_Project_Token_Here') # For SmartUI
}
options.set_capability("LT:Options", lt_options)
driver = None
try:
driver = webdriver.Remote(
command_executor=f"http://{LT_USERNAME}:{LT_ACCESS_KEY}@hub.lambdatest.com/wd/hub",
options=options,
)
driver.implicitly_wait(10)
driver.get("https://lambdatest.github.io/sample-todo-app/")
print("Successfully loaded URL: https://lambdatest.github.io/sample-todo-app/")
# Take a SmartUI snapshot
smartui_snapshot(driver, "Todo App Homepage")
driver.find_element(By.NAME, "li1").click()
smartui_snapshot(driver, "First Item Clicked")
driver.find_element(By.NAME, "li2").click()
smartui_snapshot(driver, "Second Item Clicked")
driver.execute_script("lambda-status=passed")
print("Test Finished Successfully")
except Exception as e:
if driver:
driver.execute_script("lambda-status=failed")
print(f"Test Failed: {e}")
finally:
if driver:
driver.quit()
if __name__ == '__main__':
# Make sure to set PROJECT_TOKEN environment variable if running SmartUI tests
# For Linux/macOS: export PROJECT_TOKEN="<YOUR_SMARTUI_PROJECT_TOKEN>"
# For Windows: set PROJECT_TOKEN="<YOUR_SMARTUI_PROJECT_TOKEN>"
run_lambdatest_smartui_test()
Debug
Known issues
gotchaFor SmartUI visual testing features, you must install the `@lambdatest/smartui-cli` Node.js package globally and set the `PROJECT_TOKEN` environment variable. This is an external dependency not managed by pip.fixRun `npm install -g @lambdatest/smartui-cli` and set `export PROJECT_TOKEN="<your_token>"` (or `set` on Windows) before running tests.
affects: All versions
breakingSelenium 4 introduced the W3C WebDriver standard, which changed how capabilities are structured. Ensure your capabilities are W3C compliant or properly vendor-prefixed (e.g., LambdaTest specific options should be nested under `LT:Options`) to avoid session startup failures.fixReview and update your desired capabilities object to conform to the W3C standard or use the LambdaTest capability generator for `LT:Options`.
affects: Selenium 4.x and above
gotchaThe `LT_USERNAME` and `LT_ACCESS_KEY` environment variables are crucial for authenticating with the LambdaTest cloud grid. If these are not correctly set, your `webdriver.Remote` connection will fail.fixEnsure `export LT_USERNAME="YOUR_USERNAME"` and `export LT_ACCESS_KEY="YOUR ACCESS KEY"` (or `set` on Windows) are configured in your environment before running tests.
affects: All versions
gotchaRelying on `time.sleep()` or excessively long implicit waits can lead to flaky tests, especially when dealing with dynamic web elements or network latency on a remote grid. Elements might not be ready when the script tries to interact with them.fixImplement explicit waits using `WebDriverWait` and `ExpectedConditions` to wait for specific conditions (e.g., element visibility, clickability) before interacting with elements.
affects: All Selenium versions
Errors
Common errors & fixes
selenium.common.exceptions.WebDriverException: Message: Unauthorized, either Username or AccessKey is invalid.
The LambdaTest username or access key provided in the test script or environment variables is incorrect or missing, preventing authentication with the LambdaTest grid.
fixEnsure `LT_USERNAME` and `LT_ACCESS_KEY` environment variables are correctly set with your actual LambdaTest credentials, or pass them accurately in the remote WebDriver URL. You can find these on your LambdaTest automation dashboard.
Desired capabilities are deprecated with Selenium 4
Selenium 4 has deprecated the use of `DesiredCapabilities` for setting browser options. Instead, it introduced specific `Options` classes for each browser (e.g., `ChromeOptions`, `FirefoxOptions`). LambdaTest-specific capabilities are now nested under a `LT:Options` key within these new options objects.
fixUpdate your Selenium code to use the browser-specific `Options` class (e.g., `from selenium.webdriver.chrome.options import Options`) and set LambdaTest capabilities using `options.set_capability('LT:Options', lt_options_dict)`. ModuleNotFoundError: No module named 'lambdatest_selenium_driver'
The `lambdatest-selenium-driver` Python package has not been installed in your current Python environment, or the interpreter running your script cannot locate it.
fixInstall the package using pip: `pip install lambdatest-selenium-driver`. If you have multiple Python versions, ensure you use the correct pip executable (e.g., `python3 -m pip install lambdatest-selenium-driver`).
AttributeError: 'WebDriver' object has no attribute 'smartui_snapshot'
The `smartui_snapshot` functionality is provided as a standalone function by the `lambdatest-selenium-driver` library, not as a method directly attached to the Selenium `WebDriver` object. It needs to be explicitly imported and called.
fixImport `smartui_snapshot` from `lambdatest_selenium_driver` and call it as a function, passing your `driver` instance and the snapshot name as arguments.
ConnectionRefusedError: [Errno 111] Connection refused
The test script is unable to establish a connection to the LambdaTest Selenium Grid hub. This can be due to an incorrect hub URL, network connectivity issues, or local firewall restrictions.
fixVerify that your `HUB_URL` is correctly formatted (e.g., `https://{USERNAME}:{ACCESS_KEY}@hub.lambdatest.com/wd/hub`), check your internet connection, and ensure no firewalls or proxies are blocking access to `hub.lambdatest.com`. Upgrade
Version history
1.0.9latest on PyPI · released Dec 9, 2025
Audit
Dependencies
seleniumrequiredThis library is an extension for Selenium WebDriver, requiring Selenium to function.