Skip to main content

Quality Assurance

Let’s Get Started: Selenium with Python #1

Two programmers working on some coding together

Did you know Python can prove to be a best friend of Selenium when it comes to automation testing? This blog will not only give a brief description of how it works and why it is required to know Selenium with python these days but will also help in learning automation testing using the same. I have developed a series to enhance understanding within a short period. So, let’s get started…

 

Selenium is a tool that controls web browsers by performing web automation through programs. It acts as an API between the browser and the programming language. It is free, open-source, and can be paired with multiple programming languages. As it works so well with Java, Kotlin, and C#, it has also proved to get along easily, in fact, very smoothly with Python as well. And that is what makes Selenium one of the most powerful automation tools for testers across the world.

Selpython

 

What is Python:

Somewhere or the other, we all are aware of Python being a remarkably popular, general-purpose, high-level, object-oriented, and easy-to-use programming language. From web development to machine learning, data science to automation testing, it has almost everything in its bag to serve each of you. Tell the work, and python will be ready to do it. Therefore, Python is considered to be an excellent language to be told and learned.

 

Why Selenium with Python?

With countless advanced features, Python has grown exponentially and still growing. When combined with Selenium, imagine how robust an automation framework can become. Let us see some more features which will surely convince you to give it a try.

Following are the features:

  • Effortless: Easy to code and skim
  • Lively run rate: It runs faster than other programming languages because it doesn’t have a compiler to convert lines of code. Therefore, the time required is reduced.
  • Better Support System: Various tools are present to increase the support, and therefore the most vital tool for simple user interfaces is that the WebDriver has strong bindings for Python.
  • Well Tethered: The API utilized in python helps connect to the browser through Selenium. It also helps to send standard commands of python to numerous browsers irrespective of all variations within the design of the browser.
  • Cost Efficient: Reduction in cost for business clients is a win-win situation.


Pre-requisites for Using Selenium with Python:

In order to learn Automated testing, one must have the following skillset:

  1. Basic knowledge of Python, keeping OOP fundamentals in priority
  2. Knowledge of Selenium and Web drivers
  3. A Basic understanding of Database/SQL fundamentals
  4. Understanding of Web Application to test.

 

Setting Up Selenium with Python:

To get started, three software needs to be downloaded:

  1. Python 3
  2. Pycharm – IDE used for coding
  3. Selenium

So, without further ado, let’s start the downloading process…

Python 3:

  1. Go to: https://www.python.org/downloads/
  2. Select the latest release version. 3.10.5 is the latest as of now.
  3. Select the Installer as per the bit of the system.
  4. Install –> Select the Customize Installation and don’t forget to check on “Add Python to PATH”

    Picture1

  5. Click on next, and Python will be successfully installed on your system.
  6. Once installed, reboot the system.

 

Pycharm:

  1. Go to: https://www.jetbrains.com/pycharm/download/#section=windows
  2. Download the Community version
  3. Install the Pycharm, and don’t forget to check on the “Add ‘bin’ folder to the PATH” option

    Picture2

  4. Click on next, and the Pycharm is ready to use! It will look something like this.

    Picture3

  5. Settings and themes can be customized according to one’s preference.
  6. Click on “New Project” and select the location of the project.
  7. If no interpreter is selected, make sure to go to the settings and select Python3 interpreter.

Picture4

 

Selenium:

    1. Open Command Prompt
    2. Write a command – “pip install Selenium.”
    3. It will be automatically installed.

Reboot the system again to ensure the trouble-free working of the software.

And voila!! You are good to go for the first test case.

 

My First Program with Selenium Python:

*Make sure to download the updated version of WebDriver and manage it properly in the folders.


Code:

from selenium import webdriver

driver = webdriver.Chrome(executable_path=”C:\Users\ashika.meshram\Python Selenium\Browser Webdrivers\chromedriver.exe”)

driver.get(“https://www.google.com”)

driver.maximize_window()

print(driver.title)

driver.close()

Picture5

 

Output:

Picture6

 

There’s a Long Way to Go…

This is just the beginning. Selenium with Python is mountainous, then why not take little steps to reach the summit?

More step-by-step content coming soon. Stay tuned…

If you find this blog interesting, try it and share it with those who might benefit.

Thanks for reading! Happy Learning 🙂

Thoughts on “Let’s Get Started: Selenium with Python #1”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ashika Meshram

Ashika Meshram is an associate technical consultant currently working on EHI. She is a coder girl fond of traveling and blogging.

More from this Author

Categories
Follow Us
TwitterLinkedinFacebookYoutubeInstagram