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.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors#1 Best Overall
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_elementlocates one element using a locator such as a name, CSS selector or ID.send_keystypes into an element, andclickactivates 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.
Rank #2
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.
Rank #3
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:
Rank #4
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 seleniumusing 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
Servicepath 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.
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
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.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.
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.
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.




