Recommended Free Tools
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.
- Install Python if it is not already available, then create and activate a virtual environment in your project directory.
- Install Selenium with
python -m pip install selenium. - 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.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute#1 Best Overall
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.
Rank #2
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.
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:
Rank #3
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.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →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.
Rank #4
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.
Best Value
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.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.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteQuick Recap
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
tryblock and calldriver.quit()infinallyso 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.




