{"id":15080634,"url":"https://github.com/testdotai/python-selenium-sdk-demo","last_synced_at":"2026-01-02T17:48:04.428Z","repository":{"id":102291464,"uuid":"482123017","full_name":"testdotai/python-selenium-sdk-demo","owner":"testdotai","description":"🎉 A demo/tutorial for python-selenium-sdk","archived":false,"fork":false,"pushed_at":"2022-04-16T10:18:24.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-01-23T03:29:02.478Z","etag":null,"topics":["ai","geckodriver","google-chrome","python","python3","safaridriver","selenium","selenium-python","selenium-webdriver","test-ai"],"latest_commit_sha":null,"homepage":"https://sdk.test.ai/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testdotai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-16T01:05:37.000Z","updated_at":"2022-04-16T10:20:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"ffa3260a-a1e4-4c04-bd3d-1ff14b6cb38d","html_url":"https://github.com/testdotai/python-selenium-sdk-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fpython-selenium-sdk-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fpython-selenium-sdk-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fpython-selenium-sdk-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdotai%2Fpython-selenium-sdk-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testdotai","download_url":"https://codeload.github.com/testdotai/python-selenium-sdk-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243896302,"owners_count":20365354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","geckodriver","google-chrome","python","python3","safaridriver","selenium","selenium-python","selenium-webdriver","test-ai"],"created_at":"2024-09-25T05:04:01.166Z","updated_at":"2026-01-02T17:48:04.402Z","avatar_url":"https://github.com/testdotai.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# test-ai-selenium-demo\n[![Python 3.7+](https://img.shields.io/badge/python-3.7%2B-blue)](https://www.python.org)\n[![Apache 2.0](https://img.shields.io/badge/Apache-2.0-blue)](https://www.apache.org/licenses/LICENSE-2.0)\n[![Discord](https://img.shields.io/discord/853669216880295946?\u0026logo=discord)](https://sdk.test.ai/discord)\n\nWelcome to the test.ai Selenium Python demo!\n\nThis repository contains a pre-configured project and basic tutorial, so you can hit the ground running with [test.ai enhanced Selenium](https://github.com/testdotai/python-selenium-sdk)!\n\n👉 This tutorial uses Google Chrome, but you will be able to use `test-ai-selenium` with any other browser that supports Selenium.\n\n## Pre-requisites\nBefore we get started, please ensure that you have installed the following software on your computer:\n\n* [Python](https://www.python.org) - version `3.7` or newer\n* [Google Chrome](https://www.google.com/chrome/)\n\nYou will also need a test.ai account, please visit https://sdk.test.ai (it's free!) to register.\n\n## An Introduction to the test.ai SDK\nIn the following tutorial, you will learn how to set up and run AI-enhanced Selenium with test.ai.\n\nNow that you have the pre-requisites installed, let's get started.\n\n### Download demo and setup dependencies\nPlease begin by cloning this repository to your computer.\n```bash\ngit clone https://github.com/testdotai/python-selenium-sdk-demo.git\n```\n\nNow, we'll install the required python dependencies to run this demo.\n\nPlease `cd` into the directory you just cloned\n\n👉 you may optionally create a [venv](https://docs.python.org/3/library/venv.html) to run this demo \n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n\n👉 depending on how your python installation is configured, you may need to replace the `python` command in the lines below with `python3`\n\nOn Mac/Linux, run the following commands in your Terminal:\n```bash\n# create the virtual environment\npython -m venv venv_selenium_demo\n\n# activate the virtual environment\nsource venv_selenium_demo/bin/activate\n```\n\nIf using Windows, in PowerShell, run the following commands:\n```powershell\n# create the virtual environment\npython -m venv venv_selenium_demo\n\n# activate the virtual environment\nvenv_selenium_demo\\Scripts\\Activate.ps1\n```\n\u003c/details\u003e\n\n\nNext, run the following command to configure the dependencies for this demo project:\n\n```bash\npip install -r requirements.txt\n```\n\n### Run the demo\nPlease visit https://sdk.test.ai, and log into your account.  Please copy your `API key` (in the upper right corner of your screen), you will need this for the next step.\n\n![Example API Key](https://testdotai.github.io/static-assets/shared/api_key.png)\n\nNext, `cd` into the root directory of this project and run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n```bash\npython -m demo.basic YOUR_API_KEY\n```\n👉 depending on how your python installation is configured, you may need to replace the `python` command in the line above with `python3`\n\nIf everything worked, an instance of the Chrome browser will be started and open to the [test.ai Store](https://testaistore.com) (no, it's not a real store!).  Then, the sample code in this demo will click the `Accesories` navbar link, click on the image for `Anchor Bracelet`, add it to the cart, and then visit the cart.\n\nThus far, the demo is using the standard Selenium selectors without any AI, which is how apps today are commonly tested.  However, selectors such as these are fragile and break easily, as even minor changes to a website may cause them to *immediately* stop working.  Fortunately, the test.ai SDK is equipped to help you avoid this unecessary hassle.\n\n### Using test.ai with Selenium\n\nThe test cases you just ran also uploads elements to https://sdk.test.ai for training the AI element classifier.  This means that even if a developer makes a change that breaks one of your selectors, test.ai can step in and still find that element.\n\nTraining takes a few minutes, you can check training status by visiting https://sdk.test.ai/training_status\n\n![training status](https://testdotai.github.io/static-assets/selenium-demo/training_status.png)\n\n⚠️ Please wait for training status of all elements to reach 100% before continuning to the next step (refresh the page to view updates)\n\nNow let's simulate what happens when a developer changes a web application's code.\n\nIn the IDE of your choice, please open [demo/basic/__main__.py](demo/basic/__main__.py).  This Python file contains an abridged form of what you might find in typical Selenium-based test suite.\n\nA few noteworthy items in this file:\n* The `Chrome` driver gets passed as a parameter to a `TestAiDriver`, along with your API key.\n* Each call to a \"`find_element_by`\" method contains a second parameter, which is used to give the returned element an optional, human-readable label for use at https://sdk.test.ai\n\nAs you can see, it is very easy to integrate test.ai into your existing Selenium-based test cases.\n\nNow, let's change a couple of the selenium selectors:\n\n```python\n# Change this line:\naccessories_nav_link = driver.find_element_by_id(\"menu-item-671\", \"accessories_nav_link\")\n\n# to:\naccessories_nav_link = driver.find_element_by_id(\"my-developers-changed-this\", \"accessories_nav_link\")\n```\n\n```python\n# Change this line:\nanchor_bracelet = driver.find_element_by_xpath('//*[@id=\"main\"]/div/ul/li[1]/div[1]/a', \"anchor_bracelet\")\n\n# to:\nanchor_bracelet = driver.find_element_by_xpath('//*[@id=\"main\"]/my/developers/also/changed/this', \"anchor_bracelet\")\n```\n\n```python\n# Change this line:\nview_cart = driver.find_element_by_css_selector(\"#main \u003e div \u003e div.woocommerce-notices-wrapper \u003e div \u003e a\", \"view_cart\")\n\n# to:\nview_cart = driver.find_element_by_css_selector(\"#main \u003e wow \u003e these \u003e developers \u003e have \u003e been \u003e busy\", \"view_cart\")\n```\n\nAs you may have already guessed, a standard Selenium test would certainly fail, but test.ai won't!\n\n### Re-run using AI selectors\nSave your changes, and using your terminal, `cd` into the root directory of this project.  Then, run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n\n```bash\npython -m demo.basic YOUR_API_KEY\n```\n\nThe demo will repeat the same steps that it performed previously, only this time, it's using test.ai!  The \"*developer's breaking changes*\" we introduced in the code have no effect on the test's ability to run, all thanks to test.ai AI.\n\n### AI-selectors only\nLet's take things a step further.\n\nIn the section above, we learned that the selenium selectors doesn't even have to be correct in order for test.ai to work, so let's just rid of them completely.\n\nPlease make the following change to [demo/basic/__main__.py](demo/basic/__main__.py):\n\n\n```python\n# Change this code:\naccessories_nav_link = driver.find_element_by_id(\"my-developers-changed-this\", \"accessories_nav_link\")\naccessories_nav_link.click()\n\nsleep(2)\n\nanchor_bracelet = driver.find_element_by_xpath('//*[@id=\"main\"]/my/developers/also/changed/this', \"anchor_bracelet\")\nanchor_bracelet.click()\n\nsleep(2)\n\nadd_to_cart = driver.find_element_by_xpath('//*[@id=\"product-2707\"]/div[2]/form/button', \"add_to_cart\")\nadd_to_cart.click()\n\nsleep(2)\n\nview_cart = driver.find_element_by_css_selector(\"#main \u003e wow \u003e these \u003e developers \u003e have \u003e been \u003e busy\", \"view_cart\")\nview_cart.click()\n\n\n# to:\naccessories_nav_link = driver.find_by_element_name(\"accessories_nav_link\")\naccessories_nav_link.click()\n\nsleep(2)\n\nanchor_bracelet = driver.find_by_element_name(\"anchor_bracelet\")\nanchor_bracelet.click()\n\nsleep(2)\n\nadd_to_cart = driver.find_by_element_name(\"add_to_cart\")\nadd_to_cart.click()\n\nsleep(2)\n\nview_cart = driver.find_by_element_name(\"view_cart\")\nview_cart.click()\n```\n\nSave your changes, and using your terminal, `cd` into the root directory of this project.  Then, run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n\n```bash\npython -m demo.basic YOUR_API_KEY\n```\n\nAs you can see, the test continues to run as if nothing happened, despite the complete absence of selenium selectors!\n\nThis is the power that test.ai AI brings to your tests.  Say goodbye forever to fragile, breaking selenium selectors.\n\n### Interactive Mode\n\nBut, we're not done yet!  The test.ai SDK also includes a novel, exciting way to create test cases using an GUI, minimaial code, and no fragile Selenium selectors.\n\nBefore we begin, let's remove the elements from our last test.\n\nVisit https://sdk.test.ai (if prompted to login, please do so) and delete all the elements on the screen.\n\n![delete elements](https://testdotai.github.io/static-assets/selenium-demo/delete_elements.gif)\n\nNext, in the IDE of your choice, please open [demo/interactive/__main__.py](demo/interactive/__main__.py).\n\nThis is a simple test which starts at https://testaistore.com/, clicks on the `Store` navbar link, searches for `Shoes`, and adds a pair of green shoes to the cart.\n\n🎥 Click [here](https://testdotai.github.io/static-assets/selenium-demo/no_ai_example_flow.mov) to see a video of the expected behavior.\n\nYou'll notice that there are no selenium selectors in this python file!  This is because test.ai includes an interactive test composer which allows you to visually select the elements to use in your tests.\n\nLet's get started.  `cd` into the root directory of this project.  Then, run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n\nOn Mac/Linux, run the following commands in your Terminal:\n```bash\nTESTAI_INTERACTIVE=1 python -m demo.interactive YOUR_API_KEY\n```\n\nIf using Windows, in PowerShell, run the following commands:\n\n```powershell\nset TESTAI_INTERACTIVE=1\npython -m demo.interactive YOUR_API_KEY\n```\n\nAfter a few seconds, a new browser window pointing to https://sdk.test.ai will open.\n\n👉 If you are prompted to login to your test.ai account, please do so. \n\nOn this new page, find the navbar link for `Store`.  Using your mouse, click and drag a box around the link.  A green box will appear as you drag your mouse.  Release your mouse button to save the selection.\n\n![store nav link demo](https://testdotai.github.io/static-assets/selenium-demo/store_nav_link.gif)\n\nBelieve it or not, you just used AI!  test.ai is visual-based, so there's no need to mess around with Selenium selectors.  The test.ai classifier will train itself using the element inside the box you just drew with your mouse, and now, when it encounters this element in the future, it will be able to recognize it!  \n\n👉 If you made a mistake while drawing your box, that's totally okay!  Just move your mouse to the correct location and simply click and drag to draw a new box.\n\nAt this point, the test will continue, and your browser window will be refreshed when its time to identify the next element.\n\nWhen prompted, please draw boxes around the elements, as demonstrated below:\n\n#### `search_products_input`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![search products input demo](https://testdotai.github.io/static-assets/selenium-demo/search_products_input.gif)\n\u003c/details\u003e\n\n#### `search_button`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![search button demo](https://testdotai.github.io/static-assets/selenium-demo/search_button.gif)\n\u003c/details\u003e\n\n#### `green_shoes`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![green shoes demo](https://testdotai.github.io/static-assets/selenium-demo/green_shoes.gif)\n\u003c/details\u003e\n\n#### `add_to_cart`\n\u003cdetails\u003e\n  \u003csummary\u003e(click to expand)\u003c/summary\u003e\n  \n![add to cart demo](https://testdotai.github.io/static-assets/selenium-demo/add_to_cart.gif)\n\u003c/details\u003e\n\nAt this point, the test is complete, and all the elements you just selected will be used to train the test.ai AI classifier.\n\n⚠️ Please wait for training status of all elements to reach 100% before continuning to the next step, you can check training status by visiting https://sdk.test.ai/training_status (refresh the page to view updates)\n\nLet's re-run this test.\n\n`cd` into the root directory of this project.  Then, run the following command, replacing the text `YOUR_API_KEY` with your test.ai API key.\n\n```bash\npython -m demo.interactive YOUR_API_KEY\n```\n\nYou'll see that the test runs to completion, interacting with all the elements you drew boxes over!  test.ai AI is 100% based on computer-vision, which means that even if your developers make changes to the underlying HTML/CSS of your web application, the tests you just definied will continue to work!\n\nAnd that's all folks, you've made it to the end of the tutorial!  🎉\n\nPlease feel free to experiment more with this code and try out some of the other selectors.  Good luck and have fun!\n\n## Additional Resources\n\u003c!-- * [API docs](https://www.javadoc.io/doc/ai.test.sdk/test-ai-selenium) --\u003e\n* [Another Basic Tutorial](https://sdk.test.ai/tutorial)\n\n## Contact\nQuestions?  Comments?  We'd love to hear from you!\n\n* ✉️ Email us: `sdk {at} test.ai`\n* 💬 Chat with us on Discord: https://sdk.test.ai/discord","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdotai%2Fpython-selenium-sdk-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestdotai%2Fpython-selenium-sdk-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdotai%2Fpython-selenium-sdk-demo/lists"}