Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesSelenium WebDriver lets a script control a real browser: open a page, find elements, enter text, click, and inspect what happens. This beginner tutorial uses Python and Selenium’s official sample form to build a complete local script, then explains setup, reliable waits, navigation settings, and common browser interactions.
What Selenium WebDriver controls
Your test code calls Selenium’s Python binding, which sends WebDriver commands to a browser-specific driver; the driver communicates with the browser. Selenium describes WebDriver as driving browsers natively, either locally or through Selenium Server. Its documentation characterizes the WebDriver standard as a W3C Recommendation. Selenium WebDriver overview
WebDriver is suited to browser-level work such as navigating pages and interacting with rendered controls. Selenium’s overview also describes WebDriver BiDi, which uses a WebSocket connection for browser events such as network requests and console messages. That is distinct from the command-and-response interaction used in the basic example below.
Set up Python, Selenium, and a browser
This example uses Python 3, the Selenium Python binding, and Google Chrome. Choose the binding that fits your project if you use another language; the import statements and APIs are language-specific, not interchangeable. Selenium’s getting-started material identifies a language binding, browser, and driver as the basic components. Selenium Manager is used by Selenium bindings by default to help manage browser and driver setup, but it cannot guarantee that every machine’s network, permissions, or browser compatibility issues will be resolved automatically. Selenium getting started
Recommended Free Tools
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
- Install Python 3 if it is not already available.
- Install the Selenium package in the environment for this script:
python -m pip install selenium. - Install or make available a supported browser, such as Chrome. Selenium Manager may handle driver management when you create the session; if browser or driver management fails, review the driver guidance and the error details. Selenium driver location troubleshooting
- Save the code below as
first_selenium.py, then runpython first_selenium.pyfrom that environment.
This creates a local browser session. Selenium can also run against a remote browser through Selenium Server; remote execution changes how the session is created and depends on the server and browser configuration in your environment.
Write a complete first Selenium script
The sample form is provided by the Selenium project. The script creates a session, opens the form, reads the title, locates the text field, types a value, clicks the submit button, waits for the response message, prints it, and quits the browser session.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
def main():
driver = webdriver.Chrome()
try:
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
print("Page title:", driver.title)
text_input = driver.find_element(By.NAME, "my-text")
text_input.send_keys("Selenium WebDriver")
driver.find_element(By.CSS_SELECTOR, "button").click()
message = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.ID, "message"))
)
print("Result:", message.text)
finally:
driver.quit()
if __name__ == "__main__":
main()
The official first-script example demonstrates the same form and basic sequence using name, CSS selector, and ID locators. This version uses a condition-specific explicit wait for the result rather than relying on a global lookup delay. Selenium first script
What each action does
webdriver.Chrome()starts a Chrome session and returns a driver object for issuing commands.driver.get(...)navigates to the form.driver.titlereads the current document title.find_element(By.NAME, "my-text")finds the text field by its name attribute;send_keys()types into it.find_element(By.CSS_SELECTOR, "button")finds the button using a CSS selector;click()activates it.WebDriverWait(...).until(...)waits for the result element to become visible before reading its text.- The
finallyblock callsquit()even if an earlier step raises an exception, closing the session and browser started by this script.
Choose locators that identify the intended element
A locator answers “which element?” It does not prove that the element is ready for the next interaction. Prefer identifiers tied to the page’s intended structure, such as a stable ID or name, when available. CSS selectors can target attributes, classes, or structure, but a broad selector such as button can match the wrong control if the page has multiple buttons. Selenium’s locator documentation explains the available strategies. Selenium element locators
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
The example uses the sample page’s name, button selector, and message ID. On a different site, inspect the page and choose a locator that uniquely selects the control. If the page renders the element later, locate it through a wait for the relevant condition rather than assuming it exists immediately.
Wait for the state your next action needs
A navigation command returning does not necessarily mean a dynamic application has finished rendering the specific control your script needs. Selenium’s waiting guidance treats synchronization with application state as a common browser-automation challenge. Use an explicit wait when you know what condition must be true before proceeding. Selenium waiting strategies
Explicit waits: condition-specific
WebDriverWait(driver, 10).until(condition) repeatedly checks a condition until it succeeds or the timeout is reached. In the first script, the condition is that the result element identified by ID is visible. Other expected conditions can wait for presence, clickability, title changes, or other supported states. The timeout is a maximum wait, not a fixed pause: the script continues when the condition succeeds.
Implicit waits: global element-lookup delay
An implicit wait applies to element lookups across the driver session. If a lookup cannot find an element immediately, Selenium keeps trying until the implicit timeout expires. This can be convenient for a broad default, but it does not express a particular application condition such as visibility or clickability.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Do not casually combine wait types
Selenium warns that mixing implicit and explicit waits can produce unpredictable combined timing. Prefer one clear strategy; for this example, the explicit wait states exactly what the next read depends on. The official short first-script demonstration includes an implicit-wait placeholder for simplicity, but a condition-specific explicit wait is a better fit when a particular state must be reached.
Set navigation behavior separately from application waits
Page-load strategy controls when a navigation command returns; it does not establish that a particular dynamically rendered element is ready. Selenium documents three strategies. Selenium browser options
| Strategy | Navigation waits for | What it does not guarantee |
|---|---|---|
normal |
The browser’s load event. | That client-side application work or a specific element is ready. |
eager |
The DOMContentLoaded event. | That all resources or the element needed by the next action are ready. |
none |
Only the initial document download. | That the page is ready for interaction. |
Use the default behavior unless you have a reason to change navigation timing. Whichever strategy you choose, add an explicit wait for the application condition required by the next command.
Useful browser interactions beyond the form
Selenium’s interaction examples cover common tasks such as reading the current URL, handling alerts, cookies, frames, and tabs or windows. These operations extend the same pattern used above: identify the browser or page state, perform the appropriate action, then wait for or inspect the resulting state. Selenium browser interactions
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Read the current URL
Use driver.current_url when you need to inspect where navigation ended. It is useful alongside driver.title for checking that a navigation reached the expected page.
Handle JavaScript alerts
Switch to the alert before accepting, dismissing, or reading it. If an alert appears asynchronously, wait for its presence rather than assuming it is immediately available.
Work with cookies
WebDriver exposes cookie operations through the active browser session. Cookie availability is scoped to the current browsing context and domain rules; navigate to the relevant site before interacting with its cookies.
Switch into a frame
Elements inside an iframe are not located from the top-level document until the driver switches into that frame. Switch to the frame first, perform the interaction, and switch back to the default content when finished.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Manage tabs and windows
When an action opens another tab or window, inspect the available window handles and switch to the one you need before locating its elements. Close or switch away from secondary windows deliberately so later commands target the intended context.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common first-script failures
- Driver or browser startup fails: Check that Python and Selenium are installed in the environment running the script, that a compatible browser is available, and that the error is not caused by network access or permissions needed for Selenium Manager. Consult Selenium’s driver location troubleshooting guidance if the browser driver cannot be located.
NoSuchElementException: Confirm the page loaded the expected content, the locator matches the current page, and the element is in the current frame or window. If it appears after client-side rendering, wait for its presence or visibility.TimeoutExceptionfrom an explicit wait: Verify that the expected state can occur, that the locator is correct, and that the page is in the right context. Increase the timeout only when the application legitimately needs more time; a longer timeout will not fix a wrong locator or a state that never occurs.- Click or typing fails because the element is not ready: Wait for a condition such as clickability or visibility, and check whether an overlay or different page state is blocking the intended interaction.
- The script ends but browser processes remain: Ensure session cleanup runs through
driver.quit(), preferably in afinallyblock as shown.quit()closes the session; it is different from closing only the current window. - It works locally but not remotely: Local and remote sessions have different browser and driver environments. Check the remote Selenium Server configuration, requested capabilities, browser availability, and network reachability from the machine running the test.
Or skip the browser setup
If your goal is to capture a page image or PDF rather than automate interactive browser behavior, ScreenshotNeo offers a screenshot API and MCP server. A single request can return an image or PDF, without you managing a local browser session. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://selenium.dev -o shot.webp
ScreenshotNeo removes known cookie and consent banners, newsletter popups, and chat widgets before capture, with each cleanup step configurable. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Can Selenium WebDriver run without opening a visible browser window?
Yes. Selenium browser options can configure a browser for headless operation; the exact option is browser-specific. Consult the relevant Selenium driver options documentation for the browser you use.
Does Selenium Manager remove the need to install a browser?
No. Selenium’s getting-started guidance still identifies a browser as a setup component. Selenium Manager helps manage browser and driver setup through the bindings, but it does not eliminate every browser, network, or permissions prerequisite.
Quick Recap
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.

