Module 3 · Automation with Selenium and a real project Lesson 7 of 15
Your first Selenium script in Python
Selenium drives a real browser. pip install selenium, open a page, find an element, assert its text — four lines, and you have automated a check that used to be manual.
The concept
Selenium drives a real browser from code: install it, download the driver (or let Selenium Manager do it), and write driver = webdriver.Chrome(); driver.get(url) — then find an element and act on it: driver.find_element(By.ID, 'email').send_keys('a@b.com'), .click(), and an assertion on what appeared.
Structure it as a script that does one journey end to end — open the site, search jobs, open the first result, check the apply button exists — and print a clear pass or fail per step. That single script is a credible automation portfolio item, and it is the same shape as every test suite you will ever write, just bigger.
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
try:
driver.get("http://localhost:3000/login")
driver.find_element(By.ID, "email").send_keys("a@b.com")
driver.find_element(By.ID, "password").send_keys("correct-password")
driver.find_element(By.CSS_SELECTOR, "button[type=submit]").click()
heading = driver.find_element(By.TAG_NAME, "h1").text
assert heading == "Dashboard", heading
finally:
driver.quit()Common mistakes
The mistake is writing a hundred assertions before the first one runs green. Get one line working against a real page, then add the next. Selenium errors say exactly which selector failed and what it waited for; the first one is the only one worth reading.
Worked example
driver.get("https://example.com") then find_element(By.TAG_NAME, "h1").text gives you a string you can assert on. Everything else in Selenium is a variation of find, act, assert.
Your practice task
Automate one signup-form check: open the page, type into three fields, submit, and assert the confirmation text.
Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.
Key takeaway
Selenium drives a real browser from code: install it, download the driver (or let Selenium Manager do it), and write driver = webdriver.Chrome(); driver.get(url) — then find an element and act on it: driver.find_element(By.ID, 'email').send_keys('a@b.com'), .click(), and an assertion on what appeared.
Keep your place in this course
A free account saves which lessons you have finished and unlocks the certificate. The lesson itself stays free to read.
Create free account or sign inCourse complete
You finished every lesson.
Your certificate is ready, and the projects you built are the proof to attach to an application.
Almost there
15 lessons left of 15
Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.