UI Automation using Python and Selenium: Tutorial
On This Page What is UI Automation Testing?Components of a UIMarch 05, 2026 · 7 min read · Tool Comparison
Selenium is a widely used tool for automating web applications, and Python do it easy to write and negociate trial scripts. It allows testers to simulate user actions like clicking buttons, fill out forms, and navigating pages. With support for multiple browsers and integration with frameworks like PyTest, Selenium enhances test execution and reportage. This tutorial covers everything related to UI mechanisation use Python, including fundamentals, key UI ingredient, and how to use Selenium with Python for effective test automation. UI automation testing verifies that an application & # 8217; s user interface behaves as expected by simulating existent user interactions through scripts and tools. It ensures that elements like buttons, kind, and navigation carte function correctly across different devices and browsers. using Python helps observe ocular and functional issues betimes, improving software reliability. Selenium, when used with Python, enable automated testing by interacting with web elements, executing test event, and formalise UI behavior efficiently. Read More: User interface consist of respective components, each serving a specific function establish on the application & # 8217; s needs. These components include input control, pilotage components, container, and informational constituent, all working together to create a seamless user experience. As seen above ingredient such as the button “Add to drag”, dropdown lists, checkboxes, toggle, or text fields all fall under input controls. Read More: Menus, buttons to sail to different pages, lookup bars, and breadcrumbs are all classic navigational components. For example, pictured above is a popular container called an Accordion container. For Example:Message boxes, notifications, icons, and tooltips. is a powerful mechanisation model that is extremely realize and established in its use for testing web applications. Distinguishing Features of Selenium: Also Read: UI automation using Python and Selenium is performed in this example. This explores the user interface of the site “https: //www.bstackdemo.com/” and transmit out an end-to-end user process. This summons involve activeness a typical user might do on the web application such as: Logging in & gt; Navigating to a certain headphone brand & gt; Liking product & gt; Adding a product to the cart & gt; Checking out & gt; Entering customer details and delivery address & gt; Concluding the purchase & gt; Downloading the receipt. Pre-Requisites: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Step 1: Import the needed software. from selenium signification webdriver Step 2: Navigate to the example web application. First, the driver for google chrome is installed or updated as needed. Following this, the chrome browser window is maximized to fill the screen. Finally, we navigate to “https: //www.bstackdemo.com/”, the website whose UI will be tested in this example. To ensure that the website loads properly explicit wait is employed, this makes the program wait until the url is “https: //www.bstackdemo.com/”. Also Read: Step 3: Automate User Login. The ID locater is utilise to find and tick on the sign-in button element. The is so used to find the textbox for inputting the username. The driver is switched to the active element (the textbox for username), and the key “ demouser ” are entered into this textbox. Read More: The XPath locator is use once again to encounter the textbox for entering the password. The driver is switched to the fighting component (the textbox for the password), and the keys “testingisfun99” are entered into this textbox. Once again explicit wait is employed with an expected stipulation to make the program hold until the text fields of the username and word are clickable. Lastly, the ID locator is used to find and tick the login button element. Step 4: Add a Google phone to the handcart and like another phone. The XPath factor is habituate to find and click on the “ Google & # 8221; vendor element in order to filter for google phones. The Pixel 4 ’ s like button is found using the and snap; To simulate how a exploiter may like sure products and buy others. Lastly, the XPath locator is used to add the Pixel 3 phone to the cart, and snap the checkout button. Once again explicit wait is employed with an expected condition to make the program wait until the Google vendor element, like button, add to cart button, and checkout button is clickable. Step 5: Fill in the necessary details and Checkout. At checkout a variety is provided to the user, request info such as their name and address. This programme uses the ID locater to find and click the textbox elements for this information; Explicit wait is used to wait until the textbook boxes are clickable. Once the requisite element has been launch the driver switches to this active ingredient and sends the keys pertinent to it. For example, upon finding the textbox with the ID “lastNameInput” the keys “Cooper” are sent to it as input. Step 6: Lastly Download the Receipt. Upon enrol all the mandatory information into the form to checkout, the user is led to a page with their receipt for the product. Once again explicit hold is engage with an expected condition to get the program wait until the link for the reception is clickable. The ID locater is utilize to find the link to download the receipt and click on it, hence conclude one likely interaction a user may have with the web application. Output: Confirmation: Selenium and Python provide an efficient and flexible solution for automating UI testing. Combining them allows teams to enhance test reportage and performance. It besides volunteer an easy way to get started, even for those with circumscribed automation experience, and delivers robust test results that can be applied across different browser and environs. While Selenium can simulate interactions, it may not full retroflex the performance or specific behaviors of existent devices. offers entree to 3500+ real devices so you can acquit exam that check not just the look but also the responsiveness, touch interaction, and functionality of your app across a wide wide range of. # Ask-and-Contributeabout this subject with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.UI Automation using Python and Selenium: Tutorial
What is UI Automation Testing?
Components of a UI
Depending on the use there are a few major part that exist in every UI:Why choose Selenium for UI mechanisation testing
UI Testing with Selenium and Python: Example
pip install selenium
pip install webdriver_manager
from selenium.webdriver.chrome.service meaning Service from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome (service=Service (ChromeDriverManager () .install ())) driver.maximize_window () wait = WebDriverWait (driver, 60) driver.get ('https: //www.bstackdemo.com/ ') wait.until (EC.url_to_be ('https: //www.bstackdemo.com/ '))sign_in=driver.find_element (By.ID, `` signin '') sign_in.click () WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, `` /html/body/div/div [2] /div/form/div [2] /div [1] /div/div [1] /div [1] ''))) .click () WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, `` /html/body/div/div [2] /div/form/div [2] /div [1] /div/div [1] /div [1] /div [1] ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` demouser '') active_ele.send_keys (Keys.ENTER) WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, `` /html/body/div/div [2] /div/form/div [2] /div [2] /div/div [1] ''))) .click () WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, `` /html/body/div/div [2] /div/form/div [2] /div [2] /div/div [1] /div [1] ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` testingisfun99 '') active_ele.send_keys (Keys.ENTER) sign_in=driver.find_element (By.ID, `` login-btn '') sign_in.click ()
# Select a Google phone and add it to the pushcart WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, `` /html/body/div/div/div/main/div [1] /div [3] /label/span ''))) .click () # Like a phone WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, `` /html/body/div/div/div/main/div [2] /div [2] /div [1] /button ''))) .click () WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.XPATH, '' /html/body/div/div/div/main/div [2] /div [3] /div [4] ''))) .click () WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.CLASS_NAME, '' buy-btn ''))) .click ()
# Checkout WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.ID, `` firstNameInput ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` Alice '') active_ele.send_keys (Keys.ENTER) WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.ID, `` lastNameInput ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` Cooper '') active_ele.send_keys (Keys.ENTER) WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.ID, `` addressLine1Input ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` Apt.5, Downton Building, Cherryblossom Road '') active_ele.send_keys (Keys.ENTER) WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.ID, `` provinceInput ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` Canterbury '') active_ele.send_keys (Keys.ENTER) WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.ID, `` postCodeInput ''))) .click () active_ele = driver.switch_to.active_element active_ele.send_keys (`` CT3 '') active_ele.send_keys (Keys.ENTER)
WebDriverWait (driver, 20) .until (EC.element_to_be_clickable ((By.ID, '' downloadpdf ''))) .click () driver.quit ()
Conclusion
Useful Resources for Selenium and Python
Related Guides
Automate This With SUSA
Test Your App Autonomously