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

On This Page What is PyCharm?Key Features of PyCharm:March 08, 2026 · 7 min read · Tool Comparison

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

Automated testing plays a important role in modernistic software development, ensuring that application function correctly across different surround. Selenium is one of the most, allowing testers and developers to automatise interactions with web applications.

To efficiently indite and accomplish Selenium scripts, a robust is all-important. PyCharm, developed by JetBrains, is a powerful and widely used IDE for Python development. It proffer intelligent codification completion, debugging instrument, and unlined integration with, do it an excellent selection for test automation.

This guide, explores the step-by-step process of setting up Selenium in PyCharm, from installation to scat your first test script.

What is PyCharm?

PyCharmis a professional Python IDE developed by JetBrains, designed to render an efficient and user-friendly coding experience. It comes with a orbit of characteristic that facilitate developers and testers write clean, maintainable, and high-performing Python code.

With its racy potentiality, PyCharm simplifies Selenium test automation, making it leisurely to write, execute, and manage test scripts expeditiously.

Key Features of PyCharm:

  • Intelligent Code Assistance& # 8211; Auto-completion, quick fixes, and syntax highlighting.
  • Built-in Debugging & amp; Testing& # 8211; Integrated debugging tools and unit testing support.
  • Version Control Integration& # 8211; Supports Git, SVN, and Mercurial for unseamed collaboration.
  • Virtual Environment & amp; Package Management& # 8211; Easily install and manage dependencies like Selenium.
  • Cross-Platform Support-Available on Windows, macOS, and Linux.

Why use Selenium with PyCharm?

Seleniumis a powerful tool for automating web applications, and PyCharm provides an effective, feature-rich surroundings to write and manage Selenium exam scripts.

By compound Selenium ’ s mechanisation capacity with PyCharm ’ s powerful development tools, testers and developers can enhance productivity, streamline testing workflow, and ensure reliable web application testing.

Using Selenium with PyCharm offers several reward:

  • PyCharm ’ s intelligent codification windup, syntax highlighting, and debugging instrument help in writing error-free Selenium test scripts.
  • Built-in virtual environment and package direction make it easy to install and manage Selenium and other dependencies.
  • Supports pytest, unittest, and early testing fabric, simplifying tryout case structure and execution.
  • Integrated Git, GitHub, and other version control systems enable unlined collaboration on test automation projects.
  • PyCharm escape on Windows, macOS, and Linux, offering flexibility for different essay surround.

Setting up Selenium with PyCharm

Before setting up Selenium in PyCharm, ensure you receive the following prerequisite:

  • Python Installed– Selenium necessitate Python to run. Download and instal the latest variant frompython & # 8217; s official site.
  • PyCharm Installed– Download and install PyCharm (Community or Professional edition) fromjetbrains.
  • pip (Python Package Manager)– Comes pre-installed with Python and is used to establish Selenium and early dependencies.

Once these requirement are met, you ’ re ready to set up Selenium in PyCharm. In the adjacent section, we ’ ll guide you through the facility and configuration operation.

Configuring PyCharm for Selenium

Now that the prerequisites are in spot, postdate these steps to instal and configure Selenium in PyCharm:

Step 1: Create a New Python Project in PyCharm

1. Open PyCharm and click on & # 8220; New Project & # 8221;.

2. Choose a project location and assure that Virtualenv is choose as the environment.

3. Click & # 8220; Create & # 8221; to set up your labor.

Step 2: Install Selenium via pip

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

2. Run the following command to install Selenium:

pip install selenium

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

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

Step 3: Verify Installation

1. 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 erroneousness seem, Selenium is successfully instal.

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

Testing Website on Chrome and Firefox employ Selenium PyCharm: Example

Now that Selenium is establish, let & # 8217; s publish a simple test script to open a demo website in both Chrome and Firefox using Selenium in PyCharm and print it ’ s rubric.

Step 1: Write the Selenium Script

Create a new Python file (e.g., test_script.py) and add the undermentioned codification:

from selenium meaning webdriver # Launch Chrome chrome_driver = webdriver.Chrome () chrome_driver.get ('https: //bstackdemo.com/ ') mark (`` Title in Chrome: '', chrome_driver.title) chrome_driver.quit () # Launch Firefox firefox_driver = webdriver.Firefox () firefox_driver.get (`` https: //bstackdemo.com/ '') print (`` Title in Firefox: '', firefox_driver.title) firefox_driver.quit ()

Step 2: Run the Script

1. In PyCharm, open the Terminal and run below bidding.

python file_name.py

2. The script will:

  • Open Chrome and Firefox to visit & # 8220;https: //bstackdemo.com“.
  • Print the website title in both browsers like below screenshot.
  • Close the browsers after performance.

This model prove how to try websites across multiple browsers using Selenium in PyCharm efficiently.

Debugging Tests in Selenium with PyCharm

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

By set breakpoints in the playscript, testers can pause performance and dissect the state of variables, element locators, and browser interaction. Running the script in Debug Mode (Shift + F9) allows stepping through codification, inspecting variable value, and get errors in real time. The Console output helps track deal traces and exclusion for quick matter resolution.

We can use print () for debugging, which provides canonic output but deficiency control over log levels and file storage. However, the logging module allows better debugging with different log levels (INFO, WARNING, ERROR) and the power to store logs for later analysis, so normally, 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 consistently, making debugging more effectual and manageable.

Note:If employ the pytest model, 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

Following best practices while using PyCharm with Selenium facilitate improve code efficiency, maintainability, and debugging capabilities.

  • Use Virtual Environments:Create a virtual environment for your Selenium project to forefend dependency conflicts.
  • Follow Proper Logging:Instead of usingprint(), utilize Python ’ s log module for better debugging and log management.
  • Use Explicit Waits:Rely on explicit wait (WebDriverWait) instead of implicit waits ortime.sleep ()for better trial stableness.
  • Organize Test Scripts: Structure your examination scripts use functions or frameworks like pytest for better reusability and scalability.
  • Enable PyCharm ’ s Code Assistance:Use PyCharm ’ s built-in inspections, code proposition, and auto-formatting for cleaner code.
  • Use Page Object Model (POM):Implement POM to separate test logic from UI interactions, making test maintenance easy.
  • Debug Efficiently:Utilize PyCharm ’ s debugger (Shift + F9) and breakpoints for efficient troubleshooting.

Talk to an Expert

Why Use BrowserStack Automate to Run Selenium Tests on Real Devices?

Running Selenium tests on real devices ensures accurate results by replicate real-world user conditions, including different browsers, OS versions, and gimmick ironware. However, maintaining an in-house device lab is costly and time-consuming.

provides a cloud-based real-device testing platform, countenance Selenium tests to run on thousands of real devices and browsers without apparatus or maintenance hassles. It offer:

  • Access to Real Devices & amp; Browsers:Test across a vast scope of devices, browsers, and OS combinations.
  • :Run multiple tests simultaneously, reducing execution time.
  • Zero Setup & amp; Maintenance:No need to install or manage physical device or browser drivers.
  • Accurate Debugging Tools:Provides screenshots, video recordings, and logs for faster matter resolution.
  • Unseamed Integration:Works with CI/CD tools like Jenkins, GitHub Actions, and Azure DevOps for uninterrupted examination.

By using BrowserStack Automate, squad can achieve faster, more reliable, and scalable Selenium test performance on real device.

Conclusion

Setting up Selenium with PyCharm simplifies browser mechanisation, providing robust debugging and code direction features. Proper installing, contour, and best practices like habituate logging, explicit waits, and structured test playscript ameliorate efficiency and test reliableness.

Integrating cloud platforms like ensures cross-browser compatibility on. By leveraging Selenium with PyCharm effectively, team can progress scalable and true test automation frameworks for faster and more precise testing.

Tags
30,000+ Views

# Ask-and-Contributeabout this matter with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free