To automate a browser with Python, install Selenium, open a supported browser through WebDriver, navigate to a page, locate elements, interact with them, and close the session with driver.quit(). With current Selenium versions, Selenium Manager usually handles browser-driver setup, so you typically do not need to download a driver manually. You do still need a supported browser installed.
What you need before you start
- Python: Use a Python installation available from your terminal.
- Selenium: Install the Python package with pip.
- A browser: Install a browser supported by Selenium, such as Chrome for the example below.
Selenium Manager can resolve and manage browser drivers for most supported platforms and browsers in modern Selenium. Older Selenium versions, restricted networks, or special browser installations may still require explicit driver configuration. Check the Selenium Manager documentation if automatic setup fails.
Set up Selenium in a Python virtual environment
A virtual environment keeps this project’s Python packages separate from other projects. The Selenium Python API documentation recommends considering one for an isolated installation.
- Create a project folder and enter it:
mkdir selenium-startcd selenium-start - Create a virtual environment:
python -m venv .venv
On systems where the Python 3 command is namedpython3, usepython3 -m venv .venv. - Activate it:
macOS or Linux:source .venv/bin/activate
Windows Command Prompt:.venvScriptsactivate.bat
Windows PowerShell:.venvScriptsActivate.ps1 - Install Selenium:
python -m pip install selenium
For repeatable installs, record the Selenium version you chose in requirements.txt and install from that file in future environments. The official installation guide uses selenium==4.49.0 as an example pin; it is a documentation example, not a promise that this will be the latest version when you install.
Crashes, 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 minuteWindows 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 reinstall#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.
Official setup guidance: Install a Selenium library and the Selenium Python API installation documentation.
Write and run a first browser automation script
Save this as first_selenium.py. It opens Selenium’s sample form, enters text, submits it, reads the result, and closes the browser even if an operation raises an error.
from selenium import webdriver
from selenium.webdriver.common.by import By
# Selenium Manager generally handles driver setup for current Selenium versions.
driver = webdriver.Chrome()
try:
driver.get("https://www.selenium.dev/selenium/web/web-form.html")
title = driver.title
print("Page title:", title)
text_box = driver.find_element(by=By.NAME, value="my-text")
submit_button = driver.find_element(by=By.CSS_SELECTOR, value="button")
text_box.send_keys("Selenium")
submit_button.click()
message = driver.find_element(by=By.ID, value="message")
print("Result:", message.text)
finally:
driver.quit()
Run it from the activated environment with python first_selenium.py. The browser should open the sample page, submit the form, print the page title and result, then close. This follows the operations in Selenium’s official example; the code is not presented as independently tested here. See Write your first Selenium script.
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.
How the WebDriver interaction works
Start a session and navigate
webdriver.Chrome() creates a WebDriver session and returns a driver object. driver.get(url) asks the browser to navigate to the URL. Selenium’s example also reads driver.title to retrieve the current page title.
Find elements with locators
find_element returns a matching element or raises an error if it cannot find one. The sample demonstrates three locator strategies:
By.NAMEwithmy-textlocates the form input by its name attribute.By.CSS_SELECTORwithbuttonlocates a button using a CSS selector.By.IDwithmessagelocates the submitted result by its ID.
Choose a locator that identifies the intended element on the page. A selector that matches multiple elements or depends on changeable page structure can select the wrong control or stop working after a site update.
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.
Interact and inspect the result
send_keys("Selenium") enters text into the located field. click() activates the submit button. The script then reads message.text, which is the visible text content of the result element.
Close the browser session
driver.quit() ends the WebDriver session and closes the browser by default. Putting it in a finally block ensures cleanup also runs when navigation, element lookup, or interaction fails.
Wait for the page instead of racing it
A page can continue changing after navigation: JavaScript may render a control later, a request may finish asynchronously, or a result may appear only after a click. Selenium’s documentation calls synchronization with the browser’s current state one of the biggest challenges in Selenium. If a script searches too early, it may fail even though the element appears moments later.
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
Selenium’s first-script walkthrough uses an implicit wait as a simple demonstration, but describes it as rarely the best solution. Do not treat that example as a universal timing fix. For scripts that depend on a particular control or result, learn the available approaches and their trade-offs in Waiting strategies. Prefer synchronizing around the condition your next action actually needs rather than adding arbitrary delays throughout a script.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Common problems and what to check
Driver or browser setup fails
- Confirm a supported browser is installed and can launch on the machine.
- Use a current Selenium installation so Selenium Manager can handle driver setup in the usual case.
- On older Selenium versions or restricted environments, automatic driver resolution may not work; consult the Selenium Manager guidance for explicit setup options.
An element cannot be found
- Check that the locator value matches the page’s current markup and that you are searching the expected page.
- Consider whether the page renders the element asynchronously; use a suitable wait strategy before locating or interacting with it.
- Check that a CSS selector identifies the intended element rather than a different or multiple matches.
The script ends before the browser closes
Ensure session cleanup is in a finally block and calls driver.quit(). This closes the session when an earlier step raises an exception.
Automated access is blocked or disallowed
Selenium can support browser automation beyond testing, including repetitive tasks, but a site may prohibit scraping or block automated access. Check the site’s terms and ensure you have permission before automating access. The Selenium usage documentation discusses these limits: Selenium usage guidance.
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.
Where to go after the first script
For recurring browser checks, organize scripts as tests and use a test runner such as pytest; Selenium’s usage documentation includes a Python test example, although that documentation section notes it is incomplete. If you need low-code record-and-playback, Selenium IDE is another starting point. If you need to distribute execution across machines or browsers, explore Selenium Grid. These are different next steps: a local Python WebDriver script is the direct route for learning browser automation, IDE reduces coding, and Grid addresses scaled execution.
Or skip the browser setup
If your goal is to capture a webpage rather than interact with its controls, ScreenshotNeo is a website screenshot API and MCP server for developers. One GET request returns an image or PDF. Cookie banners are accepted and removed before capture, along with known consent platforms, newsletter popups, and chat widgets; these cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. AI agents can use its MCP tools: take_screenshot, get_page_info, and capture_pdf.
For example, this cURL request saves a WebP screenshot:
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 documentation for API details. ScreenshotNeo offers 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000, and every feature is on every plan. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.
Recommended Free Tools
Frequently Asked Questions
Can I use Selenium without writing a script?
Selenium IDE offers a record-and-playback route if you want a low-code starting point; this guide focuses on Python WebDriver.
Does Selenium only work for testing?
No. Selenium supports browser automation use cases beyond web-application tests, but you should respect site terms and access restrictions.
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.




