SeleniumLab

Course1 · Selenium automation → Getting Started

1 · Selenium automation

Your first automation script

10 min · Module 6

A minimal Selenium script usually follows four steps:

  1. Create a WebDriver instance.
  2. Navigate to a page.
  3. Find an element and interact with it.
  4. Quit the browser so processes do not linger.

Always call driver.quit() in a finally block or use a context manager pattern in tests.

Example / notes

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

driver = webdriver.Chrome()
try:
    driver.get("http://127.0.0.1:8000/lab/")
    heading = driver.find_element(By.TAG_NAME, "h1")
    assert "Practice" in heading.text or heading.text
    print("Opened lab hub:", heading.text)
finally:
    driver.quit()

Practice in Lab: /lab/

Log in to track progress / take quizzes
← Install Selenium and WebDriver
Modules in this track