Test Automation with Python Selenium

In this Python Selenium article we want to learn about Test Automation with Python Selenium, so Python Selenium is powerful automation tool and it is widely used for web application testing. In this tutorial we want to talk that how to automate tests using Python Selenium, and for our testing purpose we are using DemoQA website (https://demoqa.com/login).

 

 

 

Python Selenium Test Automation

For working with the example of this tutorial you need some requirements, first you should have installed Python in your system, then we need to install Python Selenium and you can use pip for that like this, also you need to driver for specific browser.

 

 

Note: You can download the drivers from here.

Chrome: https://chromedriver.chromium.org/downloads
Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox: https://github.com/mozilla/geckodriver/releases
Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/

 

 

This is the complete code for this article, basically, this code automates the process of logging in to a website using Python Selenium and verifies the success of the login operation.

 

 

Now let’s break down above, so in that code first we have imported the required classes from Python Selenium.

 

 

This creates an instance of the Chrome webdriver, which will be used to control the Chrome browser.

 

 

The get() method is used to open the specified URL in the browser.

 

 

This code waits for the username and password input fields to become visible using WebDriverWait and the visibility_of_element_located condition from EC. after that they are visible, it sends the credentials using the send_keys() method.

 

 

After entering the password, the code simulates pressing the Enter key on the keyboard (Keys.RETURN) to submit the form.

 

 

This code waits for the page title to contain DEMOQA using WebDriverWait and the title_contains condition from EC. If the title contains the specified text, it prints Login successful; otherwise, it prints Login failed.

 

 

And lastly this closes the browser and ends the webdriver session.

 

 

 

This will be the result, it will login to the website using the credentials that we have already given, also it prints the login successfully in the console.

Python Selenium Test Automation
Python Selenium Test Automation

 

 

Learn More on Python Selenium 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Codeloop
Share via
Copy link
Powered by Social Snap
×