Testing

Selenium Tutorial for Beginners: Automate a Real Browser Test

9 min read Updated June 2026

Selenium is still the most-asked automation tool in Chennai QA interviews. This tutorial covers the basics plus the stability discipline that separates a passing test from a useful one.

01.Install Selenium and a driver

Selenium 4 auto-downloads drivers via the Selenium Manager. You just `pip install selenium` and start.

$ pip install selenium pytest

02.Your first test

Open a browser, navigate to a URL, assert something on the page. That's the whole job — done well, repeatedly.

from selenium import webdriver
from selenium.webdriver.common.by import By

def test_homepage_title():
    driver = webdriver.Chrome()
    driver.get('https://www.python.org')
    assert 'Python' in driver.title
    driver.quit()

03.Locator strategies that survive redesigns

Never rely on auto-generated class names. Order of preference: explicit `data-testid` attributes, accessible roles, then CSS selectors. XPath is a last resort.

04.Explicit waits — the cure for flaky tests

Forget `time.sleep`. Use `WebDriverWait` with `expected_conditions` so your test waits exactly as long as it needs to and no more.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, '[data-testid=submit]'))
).click()

05.Wrap it in a small framework

Use pytest fixtures for the driver, the Page Object pattern for page logic, and a `conftest.py` for shared setup. That structure scales from one test to a thousand.

Take Testing from tutorial to job offer.

Our Testing programs come with projects, mentor reviews and 100% placement support.