Test Automation

How to Install Selenium in Pycharm?

Introduction

Let guide you on how to install selenium in pycharm. PyCharm, a widely-used Python IDE, enables efficient Python code development, while Selenium empowers web testing and scraping.

Install Python and pip on Windows

“Installing Python and pip on Windows is the first step in setting up your development environment. Visit the official Python website at https://www.python.org/downloads/

Verify python installation by executiong the command python –version

 python --version

/ou can also verify pip (pip is a package management system used to install and manage software packages written in Python), pip –version

pip –version

Note: Make sure you have properly added required environment variables.

Install Selenium Libraries

Now Use the given command from CMD to install selenium libraries, pip install -U selenium

It will take the latest package of selenium and will install it,Selenium get installed in the directory where python is installed e.g. c:\users\userName\appdata\local\programs\python\python36-32\lib\site-packages

Install PyCharm

If you haven’t already, you’ll need to download and install PyCharm on your computer. Download the Community (free) or Professional (paid) version from the official website: https://www.jetbrains.com/pycharm/download/

Copy the installation path for future reference in my case it is C:\Program Files\JetBrains\PyCharm Edu 2017.3

As we see that we have to choose python version, it meas that you can install pythong with the installation of pycharm, as we have already installed pythong so it does not matter what verion you select here, as we will use the one that we have already installed. Later uninstalled the python installed it with pycharm installation, if you are not gona use it.

JetBrains is nothing but a company name that has develped this open source IDE.

Create a New Python Project

Create a new project with any title on your desired location on the system. Also make sure that in pycharm IDE when creating New project you are using the python that you have installed manually not the one which is installed with pycharm IDE installation. See Create New Project snap


Add Selenium Scripts to a Project

Create a ‘Test’ directory to hold your Python code, and within it, establish a ‘drivers’ sub-directory to store various Selenium web drivers for different browsers. Download, unzip, and place these drivers in the directory from https://www.seleniumhq.org/download.

from selenium import webdriver import time class login():
 
driver = webdriver.Chrome("..\drivers\chromedriver.exe") 

driver.implicitly_wait(30) driver.maximize_window() 

driver.get("http://www.facebook.com")

username = driver.find_element_by_id("email")
password = driver.find_element_by_id("pass")
submit = driver.find_element_by_id("u_0_4")
username.send_keys("test@test.test")
password.send_keys("mykewlpass")
time.sleep(5)
submit.click()

driver.close()

Next Move

Now, development environment is ready, you can go ahead by starting you testing or anyother framework, for testin i suggest to you use unittest — Unit testing framework.

Conclusion | How to Install Selenium in Pycharm?

Installing Selenium in PyCharm empowers you to automate web tasks and perform web scraping efficiently. With Python, pip, and Selenium libraries in place, PyCharm becomes your command center for seamless development. Now, equipped with the right tools and a well-configured environment, you’re ready to embark on your web automation and testing journey.

Rashid Ali

I am an IT professional with 10 years of experience in the field of Software development. My track record of satisfied clients speaks to my proficiency in delivering top-notch services in QA manual and Automation, IT support services, Blogging , and On-page SEO.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button