Use Selenium’s Python WebDriver bindings to control a supported browser: install the package, start a driver, navigate to a page, locate and interact with elements, and wait for the page state your next step needs. For local scripts, you do not need Selenium’s Java server. Modern Selenium uses Selenium Manager to handle browser and driver setup in most supported environments.
What Selenium does in Python
Selenium lets a Python program interact with a browser through WebDriver. It can open pages, find elements, click buttons, enter text, and check resulting page state, making it useful for browser-based workflows and web application tests. The Python client documentation describes the package as being used to automate browser interaction: Selenium WebDriver documentation.
Selenium drives a real browser rather than simply downloading HTML. That is useful when the behavior being tested depends on browser-side JavaScript, user interaction, or the rendered application state. It also means that browser startup, page timing, and locator stability matter to the reliability of your script.
Install Selenium and prepare a local environment
The current SeleniumHQ Python client documentation lists Python 3.10 or newer and browser options including Chrome, Edge, Firefox, Safari, WebKitGTK, and WPEWebKit. Supported combinations depend on the browser, operating system, and Selenium release, so check the official installation documentation for the current requirements.
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.
Create an isolated Python environment
An isolated virtual environment keeps project dependencies separate from system Python packages. From your project directory, run:
python -m venv .venv
Activate it, then install or upgrade the Selenium bindings:
# macOS or Linux
source .venv/bin/activate
# Windows PowerShell
.venvScriptsActivate.ps1
python -m pip install -U selenium
Use the activation command for your shell; the Windows command above is for PowerShell. The package installation command is the one recommended by SeleniumHQ. Pinning a package version in a project dependency file can make a team’s environment reproducible, but choose a version compatible with your Python and browser setup.
Let Selenium Manager handle routine driver setup
A WebDriver session needs a browser and a way to communicate with it. In most supported environments, modern Selenium uses Selenium Manager to discover or obtain the necessary browser driver. You usually do not need to begin by downloading a driver manually. Manual browser and driver configuration remains available for environments with special requirements; see Selenium Manager before changing driver paths or versions.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →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.
Launch a browser, open a page, and close it cleanly
This complete example starts Chrome, visits a page, locates its heading by ID, prints the heading text, and always closes the browser session. The target URL and element ID are illustrative; replace them with a page and locator that exist in your application.
from selenium import webdriver
from selenium.webdriver.common.by import By
def main():
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
heading = driver.find_element(By.TAG_NAME, "h1")
print(heading.text)
finally:
driver.quit()
if __name__ == "__main__":
main()
Run it from the active virtual environment with python your_script.py. Selenium Manager may perform initial browser-driver setup, so the first launch can take longer than later launches. get navigates to the URL, find_element returns the first matching element, and quit ends the entire browser session. Put cleanup in finally so exceptions do not leave the browser running.
Find and interact with elements
Selenium provides locator strategies through By. Use the locator that best fits your markup and the stability requirements of your test. A stable ID is often a clear choice when the application provides one; CSS selectors can express useful relationships without relying on fragile layout positions.
| Locator | Example | Use |
|---|---|---|
| ID | By.ID, "email" |
Target an element with a stable, unique ID. |
| Name | By.NAME, "q" |
Target a form field by its name attribute. |
| CSS selector | By.CSS_SELECTOR, "button[type='submit']" |
Target elements using CSS selector syntax. |
| XPath | By.XPATH, "//button[@type='submit']" |
Target elements using XPath when it fits the document structure. |
| Tag name | By.TAG_NAME, "h1" |
Find elements by HTML tag, such as a heading. |
For example, to enter text and submit a form, locate the actual fields and button used by the page:
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.
from selenium.webdriver.common.by import By
email = driver.find_element(By.ID, "email")
email.send_keys("reader@example.com")
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()
Do not assume that a selector from a tutorial matches your site. Inspect the page markup, prefer selectors tied to meaningful attributes, and assert the outcome the test is meant to verify rather than merely confirming that a click command ran.
Wait for dynamic pages without flaky sleeps
A completed navigation does not guarantee that JavaScript-driven content or a target control is ready. Selenium identifies timing races as a common source of unreliable browser automation. A fixed time.sleep may be too short on a slow run and unnecessarily long on a fast one. Instead, wait for the specific condition required by the next action.
Use an explicit wait for the condition you need
This example waits up to 10 seconds for a button to become clickable before clicking it:
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(driver, 10)
submit = wait.until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']"))
)
submit.click()
The timeout is a maximum wait, not a guaranteed delay: Selenium proceeds as soon as the condition becomes true. Choose a condition that matches the next operation, such as visibility before reading displayed content or clickability before clicking. See the official waiting strategies guide for available conditions and details.
Free tools Windows power users keep installed
One-click scans. No signup required.
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
Implicit waits and the mixing warning
An implicit wait sets a default amount of time the driver will poll when locating elements. Explicit waits target a particular condition. Selenium warns not to mix implicit and explicit waits because doing so can cause unpredictable total wait times. For scripts that need condition-specific synchronization, use explicit waits consistently rather than combining wait styles.
Turn the workflow into a browser test
A useful browser test checks application behavior, not just whether Selenium launched. For instance, after submitting a form, assert that the expected confirmation appears. The following example uses Python’s standard-library unittest; replace the selector and expected text with those from your application.
import unittest
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
class ExamplePageTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
def tearDown(self):
self.driver.quit()
def test_confirmation_appears(self):
self.driver.get("https://example.com")
confirmation = WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((By.ID, "confirmation"))
)
self.assertIn("Thank you", confirmation.text)
if __name__ == "__main__":
unittest.main()
The cleanup method ensures the browser session is quit after a test. Selenium’s documentation also covers use with pytest; whichever test framework you choose, isolate test data and assert observable outcomes that matter to the application.
Choose local or remote browser execution
Local WebDriver
Run locally when developing a script or executing tests on the same machine that has the browser. The Python client documentation says a local Selenium script does not need the Java server. Local runs are straightforward, but the machine running the script must have a compatible browser environment and has finite capacity for parallel sessions.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.
Remote WebDriver and Selenium Grid
Use Selenium Grid and Remote WebDriver when the browser should run on another machine or when you need a distributed browser test setup. The remote workflow adds Grid configuration and network connectivity to the test environment. At larger scale, teams may evaluate a hosted browser-testing or Grid service, but compare providers independently: Selenium’s local/remote distinction alone does not establish a particular vendor, price, or capacity.
When deciding, account for the browsers and operating systems you must cover, who maintains the browser nodes, how many tests need to run concurrently, and whether you want to operate Grid yourself. Start locally unless remote execution solves a concrete coverage, capacity, or environment need.
Troubleshoot common Selenium problems
- Driver or browser startup fails: Confirm the browser is installed and supported in the current Selenium environment. Try the current Selenium Manager workflow before setting a manual driver path; for restricted or custom environments, consult the Selenium Manager documentation and configure the browser and driver deliberately.
NoSuchElementExceptionappears: Verify the locator against the current page markup and confirm navigation reached the expected page. If the page renders the element asynchronously, replace an immediate lookup with an explicit wait for presence or visibility.- The element is found but a click fails: The element may not yet be interactable or may be covered by an overlay. Wait for clickability, check that a consent dialog or other page layer is handled, and verify the target is the intended control.
- The test is intermittently failing: Identify the condition that must be true before the failing operation and wait for that condition. Avoid fixed sleeps as a synchronization strategy and do not mix implicit and explicit waits.
- The test passes locally but not on a remote node: Check the remote browser, operating system, network access, and browser configuration rather than assuming the local environment is identical. Remote WebDriver executes against the environment addressed by the Grid.
- Browser processes remain after a failure: Ensure every created driver is closed with
quitin afinallyblock or test teardown method.
Or skip the browser setup
If the task is simply to capture a webpage as an image or PDF, you may not need an interactive Selenium session. ScreenshotNeo is a website screenshot API and MCP server: one GET request with a URL returns a PNG, JPEG, WebP, or PDF. Its capture can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.
Install requests with python -m pip install requests, then save this as a Python script. Replace the URL with the page you want to capture and provide your API key:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
See the ScreenshotNeo API documentation for request options and response details. This is a capture service, not a replacement for Selenium when you need to click through an application, enter data, or test interactive behavior. Sign up free for 1,000 screenshots a month with no card.
Frequently Asked Questions
Does Selenium require Java to automate browsers from Python?
No. A local Python WebDriver script does not need Selenium’s Java server.
Can Selenium automate Firefox as well as Chrome?
The current SeleniumHQ Python client documentation lists both Firefox and Chrome, along with other browser options; verify support for your specific environment in its installation documentation.
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.

