Introduction
Selenium controls real browsers via a small “bridge” program called a browser driver. You can either install drivers manually (ChromeDriver, GeckoDriver, EdgeDriver, SafariDriver) or let Python’s webdriver-manager
handle it automatically. Below we show both.
Prerequisites
- Windows/Mac/Linux machine
- Python 3.8+ recommended
- PyCharm Community or Professional
- Google Chrome (or Firefox/Edge/Safari)
Install Python
- Download from python.org.
- Windows: Check “Add Python to PATH”.
- Verify:
python --version
pip --version
Install & Setup PyCharm
- Install from JetBrains.
- Create a new project (PyCharm will create a virtual environment).
- Open the built-in Terminal at the bottom panel.
Install Selenium
In PyCharm’s Terminal (or OS terminal):
pip install selenium webdriver-manager
Option A: Automatic Driver (Recommended)
webdriver-manager
downloads a compatible driver at runtime and avoids version mismatch issues.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import time
options = Options()
options.add_argument("--start-maximized")
# Auto-downloads a compatible ChromeDriver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")
time.sleep(2)
box = driver.find_element(By.NAME, "q")
box.send_keys("BBSEdTech")
box.submit()
time.sleep(3)
driver.quit()
Use Firefox or Edge with webdriver-manager
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))
driver.get("https://www.example.com")
driver.quit()
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()))
driver.get("https://www.example.com")
driver.quit()
Option B: Manual Browser Driver Setup
If your organization disallows runtime downloads or you need a fixed driver version, install drivers manually and point Selenium to them.
1) Download driver matching your browser
- Chrome → ChromeDriver (version must match your Chrome major version)
- Firefox → GeckoDriver
- Microsoft Edge → EdgeDriver
- Safari (macOS) → SafariDriver (preinstalled; enable “Develop → Allow Remote Automation” in Safari)
2) Put the driver somewhere stable
- Windows: e.g.,
C:\tools\drivers\
- macOS/Linux: e.g.,
/usr/local/bin
or inside your project
3) Point Selenium at the driver
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument("--start-maximized")
chromedriver_path = r"C:\tools\drivers\chromedriver.exe" # Update path
driver = webdriver.Chrome(service=Service(chromedriver_path), options=options)
driver.get("https://www.google.com")
time.sleep(2)
driver.find_element(By.NAME, "q").send_keys("BBSEdTech")
driver.find_element(By.NAME, "q").submit()
time.sleep(3)
driver.quit()
Manual: Firefox & Edge examples
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
gecko_path = r"C:\tools\drivers\geckodriver.exe" # Update path
driver = webdriver.Firefox(service=Service(gecko_path))
driver.get("https://www.example.com")
driver.quit()
from selenium import webdriver
from selenium.webdriver.edge.service import Service
msedge_path = r"C:\tools\drivers\msedgedriver.exe" # Update path
driver = webdriver.Edge(service=Service(msedge_path))
driver.get("https://www.example.com")
driver.quit()
Your First Automation Script
Use either Option A or Option B above, then try this minimal smoke test with a search:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager # remove if using manual path
import time
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")
time.sleep(1)
driver.find_element(By.NAME, "q").send_keys("BBSEdTech")
driver.find_element(By.NAME, "q").submit()
time.sleep(2)
driver.quit()
Service
? Selenium 4 expects drivers to be passed via Service(...)
instead of the legacy executable_path
.
Common Errors & Fixes (FAQ)
“NoSuchDriverException / driver not found”
Use webdriver-manager
or ensure the driver exists at the specified path and matches your browser version.
“This version of ChromeDriver only supports Chrome version …”
Upgrade/downgrade the driver to the same major version as your Chrome/Edge.
“ModuleNotFoundError: No module named 'selenium'”
Install Selenium in the active interpreter: pip install selenium
. In PyCharm, check Settings → Project → Python Interpreter.
Run headless
Add options.add_argument("--headless=new")
for modern Chrome/Edge headless.
macOS SafariDriver
Open Safari → Develop menu → enable “Allow Remote Automation”. Use webdriver.Safari()
(no external binary needed).
Corporate proxies / offline CI
Prefer manual drivers checked into your CI image, or pre-cache webdriver-manager
artifacts in your build environment.
Next Steps
- Use
WebDriverWait
& expected conditions. - Organize tests with PyTest & Page Object Model.
- Run UI tests in CI (GitHub Actions/Jenkins).