Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

How to Run Selenium with Chrome in Python

A practical Python guide to installing Selenium, running Chrome, interacting with a page, handling waits and fixing common startup problems.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Selenium in the same Python environment that will run your script, then start Chrome with webdriver.Chrome(). In a typical current setup, Selenium Manager finds or obtains a compatible ChromeDriver, so you usually do not need to download the driver yourself. The example below opens a page, fills in a form, waits for the result and reliably closes the browser.

Install Selenium in your Python environment

Use a virtual environment to keep this project’s dependencies separate from system Python. Run these commands from your project directory:

python -m venv .venv
# Activate .venv using the command for your operating system
python -m pip install -U selenium

On Windows, activate it with .venvScriptsactivate. On macOS or Linux, use source .venv/bin/activate. Then run the install command in that activated environment. Using python -m pip helps ensure the package is installed for the Python interpreter selected by python.

The Selenium Python documentation recommends installing or updating with pip install -U selenium; the commands above use the equivalent interpreter-qualified form. See Selenium’s Python installation instructions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run a first Chrome script

Save this as selenium_form.py and run it with python selenium_form.py. It uses Selenium’s demonstration form, enters text, submits the form, prints the page title and result, and closes the browser even if an operation raises an error.

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")
    title = driver.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(title, message.text)
finally:
    driver.quit()

What the main calls do

  • webdriver.Chrome() starts a Chrome WebDriver session.
  • driver.get(url) navigates to the page.
  • find_element locates one element using a locator such as a name, CSS selector or ID.
  • send_keys types into an element, and click activates it.
  • driver.quit() ends the browser session and releases its resources.

The locator values here match the Selenium sample page; for another site, inspect its HTML and choose a locator that identifies the intended element. Selenium’s first Python script documentation describes the same navigation and interaction pattern.

Wait for the browser state you need

A page load finishing does not necessarily mean that JavaScript-driven content is ready for the next action. Selenium’s documentation calls synchronizing code with browser state “one of the biggest challenges with Selenium,” and says its short implicit-wait example is a placeholder rather than a general solution. Prefer an explicit wait for the specific condition your next step requires.

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

wait = WebDriverWait(driver, 10)
text_box = wait.until(
    EC.visibility_of_element_located((By.NAME, "my-text"))
)
submit_button = wait.until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "button"))
)
text_box.send_keys("Selenium")
submit_button.click()
message = wait.until(
    EC.visibility_of_element_located((By.ID, "message"))
)
print(message.text)

Place these waits inside the existing try block and keep driver.quit() in its finally block. Adjust the timeout to your application’s expected behavior. Avoid casually mixing implicit and explicit waits: Selenium warns that combining wait strategies can produce confusing timing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How ChromeDriver is managed

Selenium Manager is shipped with Selenium releases starting with version 4.6. When a driver has not been supplied, Selenium’s bindings can invoke it to discover or obtain the driver needed to start the browser. That is why webdriver.Chrome() is the sensible first attempt for ordinary local use. Selenium Manager is a fallback mechanism; a driver already available through PATH or a manually configured driver can also be used. See the Selenium Manager documentation.

When you need a specific driver path

If automatic management is unsuitable in your environment, Selenium supports passing a driver path through Chrome’s Service object:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path="/path/to/chromedriver")
driver = webdriver.Chrome(service=service)

Replace the example path with the actual ChromeDriver executable path for your system. A fixed path is machine-specific, so it is less portable than allowing Selenium Manager to handle discovery. For reproducible test environments, deliberately manage and document the Python, browser and driver versions rather than assuming every machine will have the same setup.

Troubleshoot Chrome startup and script failures

Chrome will not start or the driver cannot be found

  • Confirm Chrome is installed and can launch normally.
  • Check that Selenium was installed in the active environment: run python -m pip show selenium using the same interpreter that runs the script.
  • Update Selenium in that environment with python -m pip install -U selenium, then rerun the script.
  • Record the Python, Selenium, operating-system and Chrome versions alongside the complete error message. Review Selenium Manager’s output for driver-resolution details.
  • If automatic resolution does not fit the environment, use the documented Service path approach and verify that the path points to the intended ChromeDriver executable.

An element lookup fails

Check that the locator matches the page’s current markup and that the page has reached the state in which the element exists. For content rendered asynchronously, wait for visibility or another appropriate expected condition before interacting with it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The script exits but Chrome remains open

Make sure browser work is inside a try block and driver.quit() is in its matching finally block. Calling quit() only after the last statement will not run if an earlier statement raises an exception.

Selenium’s Chrome guidance states that Selenium 4 is compatible with Chrome version 75 and greater, but that broad compatibility statement does not guarantee every platform or feature combination. Check Selenium’s current version-specific guidance when diagnosing a compatibility problem: Chrome browser documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup:

If your goal is a screenshot or PDF rather than browser interaction, ScreenshotNeo can return a capture from one GET request. Its cleanup steps can accept cookie or consent banners and remove known consent platforms, newsletter popups and chat widgets before the capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. ScreenshotNeo also offers an MCP server with screenshot, page-info and PDF tools for AI agents.

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 request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo free.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run repeatable Selenium tests

For tests, use a test framework to set up the driver, assert the page state you care about and tear the session down. Selenium’s Python examples use pytest; their repository instructions also demonstrate creating a virtual environment and installing dependencies before running tests. Keep cleanup in a fixture or a finally block so a failed assertion does not leave a browser session running. See Selenium’s Python examples.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.