Automation basics with Selenium WebDriver
Locators, waits and a first automated login test — plus what to automate and what not to.
Selenium WebDriver controls a real browser from code, so repetitive UI checks can run automatically. It supports Java, Python, C# and JavaScript; Java and Python are the most common in fresher QA jobs.
The building blocks
- Driver — opens and controls the browser.
- Locators — how you find elements:
id,name, CSS selectors, XPath. Prefer stable IDs or dedicated test attributes over long XPaths. - Actions — click, type, select, read text.
- Waits — wait for an element to be ready instead of fixed sleeps. Explicit waits make tests reliable.
- Assertions — usually from a test framework such as TestNG, JUnit or pytest.
Page Object Model
Keep each page's locators and actions in its own class. When the UI changes, you update one place instead of every test.
Automation supports manual testing; it doesn't replace it. Exploratory testing and new features still need human judgement.
Example
Practise on any app you use# Python + Selenium: automated login test (pytest) from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC
def test_valid_login(): driver = webdriver.Chrome() try: driver.get("https://qa.example-shop.test/login") driver.find_element(By.ID, "email").send_keys("anu@example.com") driver.find_element(By.ID, "password").send_keys("Kochi@2026") driver.find_element(By.CSS_SELECTOR, "[data-test=login-btn]").click()
name = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, "user-name"))) assert name.text == "Anu" finally: driver.quit()
What to notice
• Locators use IDs and a data-test attribute — stable when styling changes.
• An explicit wait (up to 10 s) replaces a fixed sleep, so the test is both faster and less flaky.
• try/finally guarantees the browser closes even when the test fails.
Apps, IDs and data are fictional examples written for practice.
Key points
- Prefer stable locators (IDs, test attributes).
- Use explicit waits, never fixed sleeps.
- Use the Page Object Model for maintainable suites.
- Automate stable, repetitive checks first.
Quick check
Why are explicit waits better than fixed sleeps?
Explicit waits continue as soon as the condition is met and tolerate slow loads, unlike fixed delays.
Practice task
Install Selenium in Python or Java and automate a search on any demo shopping site: open it, search a product, and assert that results appear.
Interview corner
What is the Page Object Model?
A design pattern where each page has a class holding its locators and actions; tests call those methods, so UI changes need updates in one place.
How do you handle a flaky test?
Find the cause — timing, test data, environment or dependencies — fix it with proper waits or isolated data, and don't simply add retries to hide it.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.