Course → 1 · Selenium automation → Getting Started
1 · Selenium automation
Your first automation script
10 min · Module 6
A minimal Selenium script usually follows four steps:
- Create a WebDriver instance.
- Navigate to a page.
- Find an element and interact with it.
- 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/
Modules in this track
- 6. Getting Started
- 7. Finding Elements
- 8. Interactions
- 9. Waits
- 10. Assertions & Structure
- 11. Page Object Model
- 12. Alerts, Frames & Windows
- 13. Headless & Next Steps