DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

7 Selenium Tutorials for Beginners: Write Your First WebDriver Test

A practical seven-step Selenium beginner tutorial: install Python Selenium, launch a browser, locate and submit a form, verify the result, and learn what to do next.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To write your first Selenium script, install a Selenium language binding, use a supported browser, start a WebDriver session, and automate a small practice form. This seven-step tutorial uses Python and Selenium 4; Selenium Manager can usually obtain the needed browser driver automatically, so downloading one by hand is not the default setup.

Selenium WebDriver is the code-based path for browser automation. The Selenium Project describes it this way: “WebDriver drives a browser natively; learn more about it.” The steps below take you from installation to a verified local test, then explain when other execution options make sense.

1. Install Selenium and prepare a browser

You need a Python installation, the Selenium Python binding, and a supported browser such as Chrome or Firefox. This tutorial uses Python 3 and the current Selenium 4 package; check the Selenium documentation for current language and browser support.

  1. Install Python if it is not already available, then create and activate a virtual environment in your project directory.
  2. Install Selenium with python -m pip install selenium.
  3. Install or update the browser you intend to automate.

Selenium code communicates with a browser through a browser-specific driver. Selenium Manager is included with Selenium releases and can manage a missing driver automatically in supported setups. In a typical beginner setup, start by running the script and let Selenium Manager handle driver management; manual driver configuration remains an option if your environment requires it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a lower-code introduction, Selenium IDE is a record-and-playback extension. Choose WebDriver when you want to learn code-based automation, assertions, and integration with a test project.

2. Start and close a WebDriver session

Save the following as first_test.py. The try/finally pattern ensures that the browser session is ended even if navigation or an assertion fails.

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


driver = webdriver.Chrome()

try:
    driver.get("https://www.selenium.dev/selenium/web/web-form.html")

    print("Page title:", driver.title)

    text_box = driver.find_element(By.NAME, "my-text")
    submit_button = driver.find_element(By.CSS_SELECTOR, "button")

    text_box.send_keys("Selenium")
    submit_button.click()

    message = driver.find_element(By.ID, "message")
    assert message.text == "Received!", f"Unexpected message: {message.text!r}"
    print("Form submission verified")
finally:
    driver.quit()

webdriver.Chrome() starts a Chrome session. To use another browser, choose its corresponding WebDriver class and ensure that browser is installed and supported in your environment.

3. Navigate and inspect the page

The first command opens Selenium’s practice form at https://www.selenium.dev/selenium/web/web-form.html. The script then reads driver.title, which lets you inspect a basic page property before interacting with the form.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the script from the environment where Selenium is installed with python first_test.py. The browser should open, load the form, perform the interaction, print the title and verification message, then close. The title is useful for orientation, but the assertion on the result message is what checks the outcome of the form action.

4. Find page elements with locators

WebDriver needs a locator to identify each control. The example uses three common locator strategies:

  • By.NAME, "my-text" finds the text field by its name attribute.
  • By.CSS_SELECTOR, "button" finds the form’s button with a CSS selector.
  • By.ID, "message" finds the post-submit result by its ID.

Prefer a locator tied to a stable, meaningful attribute when one is available. Broad selectors such as button are convenient for a known practice page, but may match the wrong element on a larger page; narrow the selector when automating your own application.

5. Enter text and trigger an action

text_box.send_keys("Selenium") types into the located field, and submit_button.click() activates the form. Keeping these operations explicit makes it easier to map each line of code to a visible browser action.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When adapting the script to another page, verify that the field and button locators identify the intended controls. If a control is disabled, covered by an overlay, or absent from the page, the interaction can fail rather than produce the result you expect.

6. Wait for and verify an outcome

The example form responds to submission by displaying a result message. The script finds the element with ID message and asserts that its text is Received!. If the assertion fails, Python raises an error instead of silently treating the run as successful.

This small example reads the result immediately because the practice page’s documented first-script flow does so. For applications that update asynchronously, wait for the expected condition rather than adding an arbitrary sleep. Selenium’s wait documentation explains explicit waits and expected conditions: https://www.selenium.dev/documentation/webdriver/waits/.

7. Put the script in context and choose what to learn next

A standalone script is a useful first exercise, but a test project usually adds a test runner so cases can be organized, reported, and run together. The right runner depends on your programming language and project; this tutorial does not require one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the first run local. Selenium Grid is an option when you need to distribute WebDriver execution across machines and browsers. Hosted cloud execution is another route for remote browser runs; Sauce Labs documents a Selenium quickstart. Neither Grid nor a cloud service is necessary to complete this local tutorial.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a screenshot rather than a WebDriver test, ScreenshotNeo can return an image or PDF through one GET request. Its cleanup can accept cookie or consent banners and remove supported consent platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed; response headers identify the page verdict and billing result. ScreenshotNeo also offers an MCP server for AI agents using Claude, Cursor, or another MCP client.

cURL example:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for authentication and request options. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. ScreenshotNeo is a screenshot API, not a replacement for Selenium’s browser-interaction tests.

Sign up for 1,000 free screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshooting a first Selenium run

  • Python cannot import Selenium: install the package in the same Python environment used to run the script with python -m pip install selenium. If you use a virtual environment, activate it first.
  • Driver or browser startup fails: confirm the target browser is installed and up to date, then check Selenium’s current Selenium Manager guidance. In supported setups Selenium Manager manages a missing driver; manual driver installation may be needed in restricted or specially configured environments.
  • The element cannot be found: confirm navigation completed and check that the locator matches the page’s current markup. Use a more specific locator when a selector matches multiple elements.
  • The result assertion fails: inspect the actual message printed in the assertion error and check whether the page has updated asynchronously. For delayed updates, use an explicit wait for the expected element or condition.
  • The browser remains open after an error: keep browser actions inside the shown try block and call driver.quit() in finally so cleanup runs when an exception occurs.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.