{"id":5985,"library":"lambdatest-selenium-driver","title":"LambdaTest Selenium Driver","description":"The lambdatest-selenium-driver is a Python SDK for integrating SmartUI visual regression testing with Selenium tests on the LambdaTest cloud grid. It facilitates running automated cross-browser compatibility and visual tests across a wide range of browser and operating system environments. Currently at version 1.0.9, the library is actively maintained, with associated repositories showing regular updates and support for the latest Selenium versions.","status":"active","version":"1.0.9","language":"python","source_language":"en","source_url":"https://github.com/LambdaTest/lambdatest-python-sdk","tags":["lambdatest","python","selenium","sdk","testing","cloud","automation","visual testing","smartui"],"install":[{"cmd":"pip install lambdatest-selenium-driver","lang":"bash","label":"Install library"},{"cmd":"npm install -g @lambdatest/smartui-cli","lang":"bash","label":"Install SmartUI CLI (for visual testing)"}],"dependencies":[{"reason":"This library is an extension for Selenium WebDriver, requiring Selenium to function.","package":"selenium","optional":false}],"imports":[{"symbol":"smartui_snapshot","correct":"from lambdatest_selenium_driver import smartui_snapshot"},{"note":"Used for connecting to the LambdaTest remote Selenium grid.","symbol":"webdriver.Remote","correct":"from selenium import webdriver"},{"note":"Or `FirefoxOptions`, etc., for browser-specific capabilities.","symbol":"Options","correct":"from selenium.webdriver.chrome.options import Options as ChromeOptions"}],"quickstart":{"code":"import os\nfrom selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options as ChromeOptions\nfrom selenium.webdriver.common.by import By\nfrom lambdatest_selenium_driver import smartui_snapshot\n\nLT_USERNAME = os.environ.get('LT_USERNAME', '')\nLT_ACCESS_KEY = os.environ.get('LT_ACCESS_KEY', '')\n\nif not LT_USERNAME or not LT_ACCESS_KEY:\n    print(\"Please set LT_USERNAME and LT_ACCESS_KEY environment variables.\")\n    exit(1)\n\ndef run_lambdatest_smartui_test():\n    options = ChromeOptions()\n    options.browser_version = \"latest\"\n    options.platform_name = \"Windows 10\"\n    \n    lt_options = {\n        \"username\": LT_USERNAME,\n        \"accessKey\": LT_ACCESS_KEY,\n        \"build\": \"Python SmartUI Build\",\n        \"project\": \"My SmartUI Project\",\n        \"name\": \"SmartUI Sample Test\",\n        \"w3c\": True,\n        \"plugin\": \"python-python\",\n        \"smartUI.project\": os.environ.get('PROJECT_TOKEN', 'Your_SmartUI_Project_Token_Here') # For SmartUI\n    }\n    options.set_capability(\"LT:Options\", lt_options)\n\n    driver = None\n    try:\n        driver = webdriver.Remote(\n            command_executor=f\"http://{LT_USERNAME}:{LT_ACCESS_KEY}@hub.lambdatest.com/wd/hub\",\n            options=options,\n        )\n\n        driver.implicitly_wait(10)\n        driver.get(\"https://lambdatest.github.io/sample-todo-app/\")\n        print(\"Successfully loaded URL: https://lambdatest.github.io/sample-todo-app/\")\n\n        # Take a SmartUI snapshot\n        smartui_snapshot(driver, \"Todo App Homepage\")\n\n        driver.find_element(By.NAME, \"li1\").click()\n        smartui_snapshot(driver, \"First Item Clicked\")\n\n        driver.find_element(By.NAME, \"li2\").click()\n        smartui_snapshot(driver, \"Second Item Clicked\")\n\n        driver.execute_script(\"lambda-status=passed\")\n        print(\"Test Finished Successfully\")\n\n    except Exception as e:\n        if driver:\n            driver.execute_script(\"lambda-status=failed\")\n        print(f\"Test Failed: {e}\")\n    finally:\n        if driver:\n            driver.quit()\n\nif __name__ == '__main__':\n    # Make sure to set PROJECT_TOKEN environment variable if running SmartUI tests\n    # For Linux/macOS: export PROJECT_TOKEN=\"<YOUR_SMARTUI_PROJECT_TOKEN>\"\n    # For Windows: set PROJECT_TOKEN=\"<YOUR_SMARTUI_PROJECT_TOKEN>\"\n    run_lambdatest_smartui_test()\n","lang":"python","description":"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."},"warnings":[{"fix":"Run `npm install -g @lambdatest/smartui-cli` and set `export PROJECT_TOKEN=\"<your_token>\"` (or `set` on Windows) before running tests.","message":"For 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review and update your desired capabilities object to conform to the W3C standard or use the LambdaTest capability generator for `LT:Options`.","message":"Selenium 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.","severity":"breaking","affected_versions":"Selenium 4.x and above"},{"fix":"Ensure `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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement explicit waits using `WebDriverWait` and `ExpectedConditions` to wait for specific conditions (e.g., element visibility, clickability) before interacting with elements.","message":"Relying 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.","severity":"gotcha","affected_versions":"All Selenium versions"}],"env_vars":null,"search_vec":"'1.0.9':51 'across':38 'activ':55 'associ':58 'autom':30,76 'browser':33,43 'cloud':25,75 'compat':34 'cross':32 'cross-brows':31 'current':48 'driver':3,8 'environ':47 'facilit':28 'grid':26 'integr':14 'lambdatest':1,6,24,70 'lambdatest-selenium-driv':5 'latest':67 'librari':53 'maintain':56 'oper':45 'python':11,71 'rang':41 'regress':17 'regular':61 'repositori':59 'run':29 'sdk':12,73 'selenium':2,7,20,68,72 'show':60 'smartui':15,79 'support':64 'system':46 'test':18,21,37,74,78 'updat':62 'version':50,69 'visual':16,36,77 'wide':40","created_at":"2026-04-14T18:36:58.872757+00:00","updated_at":"2026-04-16T16:05:04.012451+00:00","problems":[{"fix":"Ensure `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.","cause":"The LambdaTest username or access key provided in the test script or environment variables is incorrect or missing, preventing authentication with the LambdaTest grid.","error":"selenium.common.exceptions.WebDriverException: Message: Unauthorized, either Username or AccessKey is invalid."},{"fix":"Update 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)`.","cause":"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.","error":"Desired capabilities are deprecated with Selenium 4"},{"fix":"Install 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`).","cause":"The `lambdatest-selenium-driver` Python package has not been installed in your current Python environment, or the interpreter running your script cannot locate it.","error":"ModuleNotFoundError: No module named 'lambdatest_selenium_driver'"},{"fix":"Import `smartui_snapshot` from `lambdatest_selenium_driver` and call it as a function, passing your `driver` instance and the snapshot name as arguments.","cause":"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.","error":"AttributeError: 'WebDriver' object has no attribute 'smartui_snapshot'"},{"fix":"Verify 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`.","cause":"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.","error":"ConnectionRefusedError: [Errno 111] Connection refused"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.9","cli_name":"","cli_version":null,"type":"library","homepage":"https://www.lambdatest.com","github":"https://github.com/LambdaTest/lambdatest-python-sdk","docs":null,"changelog":null,"pypi":"https://pypi.org/project/lambdatest-selenium-driver/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","devops","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}