Python Selenium Web Elements Introduction

This is our second article on Python Selenium, in this article we are going to learn about Web Elements Introduction in Python Selenium. in the first article we had a simple introduction to selenium and python selenium and also how you can add selenium web drivers for python programming language. you can check the link of the first article in the below.

 

 

Python Selenium Articles

1: Python Selenium Introduction & Installation 

 

 

 

Web Elements

A web page is created of many different HTML elements, such as buttons,  links, a body, labels, forms, and so on, that are named WebElements in the context of WebDriver. Together, these elements on a web page will achieve the business functionality. For example, let’s look at the HTML code of the login page of a website.

 

You can see in the above code that our login.html file is created by different web elements, for example we have text input fields for entering our password and username, also we have a button for submitting the form. and also you can see that for these web elements we have attributes, for example for input fields we have name attribute. UI Automation in selenium is mostly about locating these WebElements on a web page and  executing user actions on them. and there are different ways that you can locate a web element in a web page, for example you can use id, name, tag, xpath, that we will use some of them in this article.

 

 

 

Locating Web Elements 

OK now let’s start our example by automating Google Search page, which we want opening of the Google Search page, locating the search input field, typing something and searching for that.

 

So in the above example we are going to use the name locator of web elements, first of all we have imported the required classes, and after that we have opened our chrome browser and finding Google website.

 

 

Now in here we are locating the name attribute of input field web element like this.

 

 

 

After that we are sending the python key to the Google Search input field, and at the end we are searching that.

 

 

 

Also you can do the same functionality using the xpath like this. make sure that you have copied the xpath of the web element.

 

 

 

 

So let’s create a little complex example, in this example we are going to use Mercury Tour website, it has a nice login form for testing web elements .

 

 

So basically in this example, first of all we are going to open Mercury Tour website , there is a login form in the website, the password and username of this login form is mercury. first of all we find the locator of the two input fields with submit button, and after that we send the password and username to the input fields, and at the end we login.

 

 

 

 

Also you can watch the complete video for Python Selenium Web Elements Introduction

 

 

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Share via
Copy link
Powered by Social Snap
×