Installing Selenium WebDriver with Python and PyCharm From Scratch (on Windows)

Alex Slepinin
4 min readJun 19, 2020

--

Who wants to try some Automation? Who doesn’t?! As of today the Automation (Test Automation) is the key to success. So let me show you how to install Selenium with Python and PyCharm really quick.

Here’s my video guide for these who prefer to watch:

Installing Selenium WebDriver with Python and PyCharm From Scratch on Windows 7/8/10/11

Here are setup instructions in text:

1. Installing Python

Go to python.org, click on “Downloads” and download the latest Python version for Windows (edit: Python 3.9 doesn’t support Windows 7, so get 3.8.x). Run the file after download is complete, check “Add Python to PATH” checkbox and click “Install Now”. “Setup was successful” message will confirm the end of installation.

2. Installing Selenium WebDriver

Go to the command line: open Start Menu, type “cmd” and hit Enter. Type “pip install -U selenium” command, press Enter. You should get “Successfully installed selenium” message shortly.

3. Getting Drivers

To make selenium control a browser you need a specific driver for that browser. Let’s download drivers for Google Chrome and Mozilla Firefox for example.

Go to selenium.dev, click on “Downloads”, scroll down till “Platforms Supported by Selenium” section and open “Browsers” menu. Click on “documentation” link under Firefox, then “geckodriver releases” link. Download a Windows 32-bit or 64-bit driver, depending on your system type (see the end of this story to learn how to find your OS type).

Go back to Selenium Downloads page and click on “documentation” link under Chrome. Open the “current stable release” link and download “chromedriver_win32.zip” file.

Extract both drivers to their own folder on drive C:\ (for example “c:\se”): that might save you a trouble dealing with PATH errors later.

4. Installing PyCharm

PyCharm is Integrated Development Environment (IDE), or, simply put, it’s the code editor which makes Python programming more comfortable and efficient.

Go to jetbrains.com and click on “Tools” menu item, then on “PyCharm”. Scroll down and click on “DOWNLOAD PYCHARM NOW” button. Click on “Download” button under “Community”. When download completes run the file, click “Next” button, then “Next” again. Check “Add launchers to the PATH” and “Create Associations” checkboxes (or check all checkboxes if you want). Click “Next”, “Next” once more. Reboot the computer after setup is done: this is necessary step to update system PATHS.

Run PyCharm: open Start Menu, type “pycharm” and press Enter. Go with default settings if you asked. When PyCharm is done loading click on “Create New Project”. Give a name to your project and click on “Create” button.

Now let’s add the selenium package to our PyCharm project. Click “File”, then “Settings”. In the Setting window choose your Project and click on “Project Interpreter”. After that click on “plus” icon on the right, type “selenium” into the search field. Choose “selenium” from the results list and click “Install Package” button. Wait until the package is installed, you’ll see a message when it’s ready.

5. Testing Selenium with Chrome and Firefox

First make sure that Chrome and Firefox are both updated to the last version.

In PyCharm right click your project, select “New” and click on “Python File”. Enter a name for the file and hit Enter. Paste the code from below, just edit the path to the Chrome Driver file. Open context menu (right click) and click on “Run”. Selenium should make Chrome browser open “yahoo.com” site.

from selenium import webdriver 
driver = webdriver.Chrome(executable_path="c:\se\chromedriver.exe")
driver.get("http://yahoo.com")
Chrome is under control

Now try the following code to test Selenium on Firefox (remember to change the driver’s path):

from selenium import webdriver
driver = webdriver.Firefox(executable_path="c:\se\geckodriver.exe")
driver.get("http://yahoo.com")
“Robot“ controls the browser

That’s it! Hope your setup went smooth and pleasant. I wrote two examples of automating tasks with Selenium and Python here (need to be updated, yes):

P.S. How to find out if your Windows is 32 or 64-bit

On Windows 8/10 click: Start Menu -> “Settings” -> “System” -> “About” and see “System Type” section.
On Windows 7 click: Start Menu -> right click “Computer” -> “Properties” and see “System Type” section.

--

--

Alex Slepinin
Alex Slepinin

Responses (3)