How to Set up and Use Selenium with PyCharm: A Step-by-Step Guide

Learn how to set up Selenium in PyCharm, run browser tests, debug issues, and organize your Python automation workflow.

Last updated: 31 August 2026 12 min read

Key Takeaways

  • PyCharm gives you a structured environment to write, organize, run, and debug Selenium tests in Python from one place.
  • A reliable setup starts with the correct Python interpreter, Selenium package, browser driver configuration, and a simple test to confirm everything works.
  • Once the basics are in place, PyCharm’s debugger, terminal, and project tools make it easier to troubleshoot failures and maintain larger Selenium test suites.

Selenium and PyCharm work well together when you want to write, run, and debug browser automation tests in Python from one development environment. PyCharm gives you code completion, project management, debugging tools, and an integrated terminal, while Selenium handles browser interaction.

In this guide, I’ll show you how to set up Selenium in PyCharm, configure the required dependencies, run tests in Chrome and Firefox, and debug common issues as you build your automation workflow.

What is PyCharm?

PyCharm is a Python IDE from JetBrains that brings coding, testing, debugging, dependency management, and project organization into one workspace. It supports Python interpreters and isolated virtual environments, which makes it easier to keep Selenium dependencies specific to each project.

When I use PyCharm for Selenium automation, I can write the test, set breakpoints, inspect variables, and troubleshoot failures without constantly switching between different tools. Its built-in debugger and run configurations are particularly useful as a test suite becomes larger.

Key Features of PyCharm:

  • Code assistance: Autocomplete, code inspections, refactoring, and error detection help me catch issues while writing tests.
  • Built-in debugging: I can add breakpoints, step through Selenium tests, and inspect variables when a test fails.
  • Run and test configurations: PyCharm lets me create reusable configurations for running and debugging different parts of a test suite.
  • Python environment management: I can configure system interpreters or isolated environments such as Virtualenv, Conda, Poetry, and uv for project dependencies.
  • Integrated development tools: Features such as the terminal and version-control support help keep common development tasks within the IDE.

For Selenium projects, these features give me a cleaner way to manage the Python environment and move from writing a test to debugging it when something goes wrong.

Why Use Selenium with PyCharm?

Selenium handles browser automation, while PyCharm gives me a structured environment to write, run, debug, and maintain the Python code behind those tests. Selenium WebDriver can drive browsers locally or remotely, so pairing it with a Python-focused IDE makes the development side of test automation easier to manage.

The combination is also widely relevant to Python development. In the 2024 Python Developers Survey, which included more than 30,000 respondents, 25% named PyCharm as their main IDE. Among respondents working in web development, that figure increased to 37%.

Here is why I find the combination useful:

  • Write tests with fewer interruptions: Code completion, inspections, syntax highlighting, and quick fixes help me catch mistakes while building Selenium scripts.
  • Debug failures in the same workspace: I can set breakpoints, step through a test, and inspect variables without adding temporary print statements throughout the code.
  • Keep dependencies isolated: Virtual environments are common in Python projects. The same survey found that 62% of respondents use venv to isolate environments, while 74% use pip for dependency management. PyCharm lets me configure these tools at the project level.
  • Work with familiar test frameworks: I can structure Selenium tests with frameworks such as pytest or Python’s built-in unittest and run them directly from the IDE.
  • Manage larger test projects: As my suite grows, project navigation, reusable run configurations, Git integration, and an integrated terminal make the codebase easier to work with.
  • Develop across operating systems: PyCharm and Selenium can be used across Windows, macOS, and Linux, which gives teams flexibility when their development environments differ.

For me, the main advantage is not that PyCharm changes how Selenium works. It gives the Selenium code around it a more organized development and debugging workflow.

Setup Procedure

Before I start writing Selenium tests in PyCharm, I first make sure Python, the IDE, the project environment, and Selenium itself are configured correctly. A few checks at this stage prevent common problems later, such as PyCharm using the wrong interpreter or Selenium being installed outside the active project environment.

1. Install Python

Download and install a supported version of Python from the official Python website.

After installation, I verify that Python is available from the terminal:

python --version

On some systems, particularly macOS or Linux, I may need to use:

python3 --version

Python version check

2. Install PyCharm

Download and install PyCharm from JetBrains. Once it is installed, I can create a new Python project or open an existing automation project.

3. Configure the Python Interpreter

PyCharm needs a Python interpreter before it can run the project. I can check this from:

Settings/Preferences → Python → Interpreter

For Selenium projects, I prefer using a separate virtual environment rather than installing every dependency globally. PyCharm supports system interpreters as well as environments such as Virtualenv, Conda, Poetry, and uv.

If I want to create a virtual environment manually, I can run:

python -m venv .venv

A virtual environment keeps the Selenium packages for this project isolated from other Python projects on the same machine.

4. Check pip

I use pip to install Selenium and other Python dependencies. To confirm it is available, I run:

python -m pip --version

PIP version check

Using python -m pip also helps ensure that the package is installed for the same Python interpreter I am using to run the project. Python recommends virtual environments for keeping project packages isolated.

5. Install Selenium

With the correct interpreter or virtual environment selected, I install the Selenium Python bindings:

python -m pip install selenium

Selenium’s documentation recommends installing the language bindings as part of the automation project rather than treating WebDriver as a standalone installation.

I can then confirm the installation with:

python -m pip show selenium

Selenium version check

6. Make Sure a Browser Is Available

For a basic local test, I need a supported browser such as Chrome, Firefox, or Edge.

With current Selenium versions, I usually do not need to manually download and configure ChromeDriver or GeckoDriver. Selenium includes Selenium Manager, which can detect the required driver and manage it automatically when one has not already been configured.

For example, this is enough to start Chrome in a standard Selenium setup:

from selenium import webdriver



driver = webdriver.Chrome()

driver.quit()

7. Run a Quick Setup Check

Before building a complete test, I create a simple Python file such as test_setup.py:

from selenium import webdriver



driver = webdriver.Chrome()

driver.get("https://example.com")



print(driver.title)



driver.quit()

Run a Quick Setup Check

If the browser opens, loads the page, prints the page title, and closes without an error, I know the basic Selenium and PyCharm setup is working.

At this point, the environment is ready for writing and running Selenium tests from PyCharm.

Configuring PyCharm for Selenium

Now that the prerequisites are in place, follow these steps to install and configure Selenium in PyCharm:

Step 1: Create a New Python Project in PyCharm

1. Open PyCharm and click on “New Project”.

Create New Project in PyCharm

2. Choose a project location and ensure that Virtualenv is selected as the environment.

Choose Project Location. for New PyCharm Project

3. Click “Create” to set up your project.

Step 2: Install Selenium via pip

1. Open the Terminal in PyCharm. (Marked in below image)

Open Terminal in PyCharm

2. Run the following command to install Selenium:

pip install selenium

3. Wait for the installation to complete. You should see a success message confirming Selenium is installed.

Selenium Installation Complete in PyCharm

Step 3: Verify Installation

1. Open the Python Console in PyCharm.

Open the Python Console in PyCharm

2. Run the following command to check if Selenium is installed correctly:

import selenium

print(selenium.__version__)

3. If no errors appear, Selenium is successfully installed.

Verify PyCharm Installation

With Selenium installed and configured in PyCharm, you’re now ready to write and execute your first Selenium test script.

Run Selenium Tests in Chrome and Firefox from PyCharm

Once Selenium is installed and the Python interpreter is configured, I like to run a simple cross-browser test to confirm that the setup works correctly. The following example opens the same page in Chrome and Firefox, prints the page title, and then closes each browser.

Step 1: Create the Selenium Test

In PyCharm, create a new Python file such as test_browsers.py and add:

from selenium import webdriver



url = "https://example.com"



# Run in Chrome

chrome_driver = webdriver.Chrome()

chrome_driver.get(url)



print("Title in Chrome:", chrome_driver.title)



chrome_driver.quit()



# Run in Firefox

firefox_driver = webdriver.Firefox()

firefox_driver.get(url)



print("Title in Firefox:", firefox_driver.title)



firefox_driver.quit()

Create the Selenium Test

Here, I use the same URL for both browsers so I can quickly confirm that Selenium can launch each browser, load the page, and access its properties.

Step 2: Run the Test in PyCharm

I can right-click the Python file and select Run, or execute it from PyCharm’s integrated terminal:

python test_browsers.py

If the system uses python3, I can run:

python3 test_browsers.py

Step 3: Check the Result

During execution, the script will:

1. Open the page in Chrome.

2. Print its title in the console.

Running PyCharm Script

3. Close Chrome.

4. Repeat the same steps in Firefox.

The output should look similar to:

Title in Chrome: Example Domain

Title in Firefox: Example Domain

This gives me a quick way to confirm that the Selenium project is working across more than one browser before I move on to writing larger test cases.

Debugging Tests in Selenium with PyCharm

Debugging helps identify and fix issues in Selenium test scripts efficiently. PyCharm provides powerful debugging tools such as breakpoints, variable inspection, and step-by-step execution control.

By setting breakpoints in the script, testers can pause execution and analyze the state of variables, element locators, and browser interactions. Running the script in Debug Mode (Shift + F9) allows stepping through code, inspecting variable values, and catching errors in real time. The Console output helps track stack traces and exceptions for quick issue resolution.

We can use print() for debugging, which provides basic output but lacks control over log levels and file storage. However, the logging module allows better debugging with different log levels (INFO, WARNING, ERROR) and the ability to store logs for later analysis, so usually, we use logging.

Example

import logging

from selenium import webdriver

# Configure logging

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

driver = webdriver.Chrome()

driver.get("https://bstackdemo.com/")

# Set a breakpoint or inspect logs

title = driver.title

logging.info(f"Page Title: {title}")

driver.quit()

With logging, test execution details are recorded systematically, making debugging more effective and manageable.

Debugging Tests in Selenium with PyCharm

Note: If using the pytest framework, we can configure the logging in the pytest.ini file as below:

[pytest]

log_cli = true

log_cli_level = INFO

log_cli_format = %(asctime)s - %(levelname)s - %(message)s

Best Practices for Using PyCharm with Selenium

As a Selenium project grows, I focus on keeping the environment, test structure, and debugging workflow easy to maintain. These practices help reduce flaky tests and make failures easier to investigate.

  • Keep dependencies isolated: I use a virtual environment for each project so Selenium and supporting packages do not conflict with dependencies from other Python projects.
  • Prefer explicit waits: I use WebDriverWait for conditions such as visibility, clickability, or page state changes instead of relying on time.sleep(). This keeps tests more responsive and reduces unnecessary delays.
  • Replace print() with proper logging: For larger suites, Python’s logging module gives me clearer control over log levels, timestamps, and failure information.
  • Structure tests with a framework: I organize tests with tools such as pytest and split reusable setup, fixtures, and test logic into separate files as the suite expands.
  • Separate page interactions from test logic: For larger applications, I use the Page Object Model to keep locators and page actions away from the assertions and business flow in the test itself.
  • Use PyCharm’s code inspections: Auto-completion, refactoring, warnings, and formatting help me catch small mistakes before I run the test.
  • Debug with breakpoints: Instead of adding temporary output statements everywhere, I use PyCharm’s debugger to pause execution, inspect variables, and step through the failing flow.
  • Keep configuration outside the test code: Browser choices, URLs, credentials, and environment-specific values are easier to maintain when they are stored separately rather than hard-coded into individual tests.

These practices become increasingly useful as a Selenium project moves from a few scripts to a reusable automation suite.

Conclusion

Using Selenium with PyCharm gives me one place to write, run, organize, and debug Python browser tests. Once the interpreter, virtual environment, Selenium package, and browsers are configured correctly, I can move from a simple script to a more structured automation project without changing tools.

As the test suite grows, features such as breakpoints, code inspections, test configurations, and project organization become more valuable. The main goal is to keep the setup simple, avoid fragile test patterns, and build the suite in a way that stays easy to debug and maintain.

Version History

  1. Aug 19, 2026 Current Version

    Refined the article with updated Selenium and PyCharm setup steps, clearer cross-browser examples, practical best practices, and improved debugging guidance.

    Venkatesh Raghunathan
    Reviewed by Venkatesh Raghunathan Full Stack Software Developer
Tags
Automation Testing Selenium Selenium Webdriver Website Testing
Grandel Robert
Grandel Robert

Senior Automation Expert

Grandel D'Souza is a software quality and test automation professional with 8+ years of experience in quality engineering and software testing. He specializes in building scalable automation solutions and helping teams improve software reliability, release velocity, and testing efficiency.

Automation Tests on Real Devices & Browsers
Seamlessly Run Automation Tests on 3500+ real Devices & Browsers