{"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":"en","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,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}