To build a basic web bot with Selenium and Python, install Selenium, start a WebDriver session, open a page, locate an element, wait for the state you need, interact with it, verify the result, and call driver.quit(). Selenium controls a real browser; it does not grant permission to automate a site. Use a target and actions you are authorized to automate.
What Selenium does—and what it does not do
Selenium’s Python bindings send WebDriver commands to a browser. That makes it useful for testing web applications and for automating permitted repetitive tasks that depend on browser behavior, such as entering a form and checking the result. Selenium is not a site-specific bot or an authorization mechanism; the rules for a particular website are not established by Selenium’s documentation.
The example below uses a local Chrome browser and a page with a visible heading. Replace the sample URL and locator with ones that match a page where your intended automation is permitted.
Install Selenium and prepare the script
The current Selenium Python API documentation lists Python 3.10 and later and gives pip install -U selenium as the installation command. Check the current API documentation for supported browser and Python details before setting up a different environment.
#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 a project directory and enter it.
mkdir selenium-bot cd selenium-bot -
Create and activate a virtual environment. On macOS or Linux:
python3 -m venv .venv source .venv/bin/activateOn Windows PowerShell:
py -m venv .venv .venvScriptsActivate.ps1 -
Install Selenium:
python -m pip install -U selenium -
Save the example in a file named
bot.py.
For most supported browser and platform combinations, Selenium Manager handles obtaining and configuring the required driver when a WebDriver is created. Manual browser or driver setup is still possible if your environment requires it; downloading a driver by hand is not a universal prerequisite.
Build a small bot with waits, a check, and cleanup
This example opens a page, waits until its first-level heading is visible, prints the heading, and fails clearly if the check is not met. The heading is a simple demonstration of locating and verifying a page element; the same pattern applies when locating an input or button on a page you are permitted to automate.
from selenium import webdriver
from selenium.common.exceptions import TimeoutException, WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
URL = "https://example.com"
TIMEOUT_SECONDS = 10
# Create one browser session for this script.
driver = webdriver.Chrome()
try:
driver.get(URL)
print(f"Page title: {driver.title}")
heading = WebDriverWait(driver, TIMEOUT_SECONDS).until(
EC.visibility_of_element_located((By.TAG_NAME, "h1"))
)
print(f"Visible heading: {heading.text}")
if not heading.text.strip():
raise RuntimeError("The heading appeared but contained no visible text.")
except TimeoutException as exc:
raise RuntimeError(
f"Timed out waiting for a visible h1 on {URL}. Check the URL and locator."
) from exc
except WebDriverException as exc:
raise RuntimeError(
"The browser session failed. Check browser availability and Selenium setup."
) from exc
finally:
# End the whole WebDriver session even if navigation or a check fails.
driver.quit()
Run it from the activated environment with python bot.py. If the page has a visible h1, the script prints its title and text. If the page does not reach the condition within ten seconds, it raises a diagnostic timeout error and still attempts to end the session.
Find an element and perform an action
For a form interaction, define locators that match the actual page. Prefer an element ID or name when available; otherwise use a CSS selector based on a stable attribute. Then wait for the input or button to be usable before acting, and verify a visible outcome after the action.
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.
# Examples only: replace these locators with selectors verified on your target page.
email = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "email"))
)
email.send_keys("[email protected]")
submit = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']"))
)
submit.click()
confirmation = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.ID, "confirmation"))
)
print(confirmation.text)
This fragment belongs inside the earlier try block, after navigation. The field name, button selector, and confirmation ID are examples, not selectors guaranteed to exist on a particular site. Use the page’s actual stable attributes and choose a confirmation condition that demonstrates the intended result.
Wait for the page state you need
A navigation reaching its configured document readiness state does not guarantee that JavaScript-rendered content or a later update is ready. Selenium identifies timing races as a common source of flaky browser automation. Wait for the condition needed by the next command—for example, visibility before reading text or clickability before clicking.
-
Use explicit waits:
WebDriverWait(driver, 10).until(...)checks for a specific expected condition and proceeds when it is satisfied or times out.Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesSpecial offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy. -
Avoid fixed sleeps:
time.sleep(5)waits the full duration even if the page is ready sooner, and may still be too short when it is slower. Selenium’s guidance recommends condition-based synchronization rather than sleeps. -
Do not mix implicit and explicit waits in one session: follow Selenium’s guidance and use explicit waits for the page conditions your script depends on.
Rank #3
SaleAnker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter- 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.
See Selenium’s Waiting Strategies for the distinction between document readiness and application readiness, and its guidance on using AI coding agents with Selenium for current recommendations on waits, locators, and cleanup.
Choose locators that survive page changes
Locators are the link between your script and the page markup. Prefer readable selectors that reflect stable page attributes:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
-
By.IDorBy.NAMEwhen the page provides a meaningful, stable ID or name. -
By.CSS_SELECTORusing stable attributes when an ID or name is unavailable—for example, a documented test attribute or a specific button type. -
Avoid selectors built from generated class names or long absolute XPath paths when a stable alternative exists. Those can be difficult to read and more likely to break when markup changes.
Rank #4
SaleUGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray- 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
Keep each locator understandable and verify it against the current target page. A selector that is valid in Python may still match no element, or may match a different element than intended.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →End the browser session reliably
Call driver.quit() when the script is finished. It ends the WebDriver session and closes its associated browser windows. Put it in a finally block so it runs after an exception as well as after success. driver.close() closes the current window or tab; it is not the general cleanup call when the whole session should end.
The script above creates a fresh session for one run. Selenium’s project guidance also recommends a fresh session per test, which helps keep browser state from one test from leaking into another.
Run locally first; use Grid only when needed
A basic script that launches Chrome on your computer does not need a Selenium server or Grid. Local WebDriver is the simplest place to learn the lifecycle and debug locators. Selenium Grid and Remote WebDriver are options when you need a browser hosted elsewhere or distributed browser sessions; they add deployment and connection details that a single local script does not require. Selenium’s Python API documentation links to remote WebDriver guidance.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common failures
| Symptom | Likely cause | What to check |
|---|---|---|
| WebDriver creation fails | The browser is unavailable, the environment has an unsupported combination, or setup could not complete. | Confirm that the browser is installed and supported by the current Selenium Python documentation. Check the exception details and environment. Selenium Manager handles most ordinary driver setup, but manual configuration may be needed in some environments. |
| The script times out waiting for an element | The URL, locator, or expected condition does not match the page, or the page did not reach that state before the timeout. | Confirm the page loaded, inspect the target page’s actual markup, and use a stable locator for an element that should be visible or clickable. Increase the wait only when a longer legitimate load is expected; do not replace the condition with an arbitrary sleep. |
| An element is found but clicking or typing does not work | The element may not yet be interactable, or the locator may identify the wrong matching element. | Wait for the appropriate condition, such as clickability, and verify that the selector identifies the intended control. |
| The browser stays open after an error | Cleanup was skipped on an exception or the script ended without quitting the session. | Place driver.quit() in a finally block and rerun the script. |
| The page looks loaded but its content is missing | Document navigation completed before client-side content or a later page update was ready. | Wait for a meaningful application condition, such as visibility of the specific result, rather than assuming navigation alone means the page is ready. |
Performance, reliability, and cost considerations
This workflow starts a real browser session, so it is suited to tasks where browser-rendered behavior matters. The official guidance reviewed here does not establish a speed benchmark against other approaches. For reliability, keep sessions short and purposeful, use stable selectors, wait for conditions rather than fixed durations, and ensure cleanup runs. The Selenium package is installed with pip; the sources cited here do not establish a monetary price for running a particular browser or hosting environment.
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 minuteBest 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.
Or skip the browser setup
If you need a screenshot rather than an interactive browser workflow, ScreenshotNeo is a website screenshot API and MCP server. Its API can return a screenshot or PDF from one GET request; the example below saves a WebP response. See the ScreenshotNeo documentation for parameters and response details.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Official Selenium references
- Selenium Client Driver — Python API documentation
- Write your first Selenium script
- Waiting Strategies
- Using AI coding agents with Selenium
Frequently Asked Questions
Does a basic Selenium script need Selenium Grid?
No. A local WebDriver script can run without a Selenium server; Grid is for remote or distributed browser sessions.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Does Selenium Manager remove the need for every manual driver setup?
No. It handles setup for most supported ordinary cases, but manual browser or driver configuration remains possible when an environment requires it.
Can I use Selenium to automate any website?
Selenium can issue browser commands, but it does not establish that a particular site permits your intended automation. Check the applicable rules and authorization for the target.
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.




