HomeSelenium

Selenium Locators – Advantages and Disadvantages of Absolute XPath Expressions

Selenium Locators – Advantages and Disadvantages of Absolute XPath Expressions

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

In the previous article, I have practically demonstrated all the Absolute XPath Expressions in detail.

In this article, I am going to explain the Advantages and Disadvantages of using Absolute XPath Expressions for locating the UI elements on the Web Pages.

Pre-requisites: In order to understand this article, you should go through the below posts first:

  1.  Installing Chropath Add-on on Chrome Browser
  2. Using Chropath Add-on in Chrome Browser
  3. Installing Selenium IDE in Chrome Browser
  4. Launching Selenium IDE in Chrome Browser

Let’s get started.

Advantages and Disadvantages of Absolute XPath Expressions

Following are the advantages and disadvantages of using Absolute XPath Expressions:

Advantages of Absolute XPath Expressions

The following are the advantages of Absolute XPath Expressions:

  • > Absolute XPath Expression locate the UI elements faster, as they contain the Complete/Full path of the UI element from the root.

For example, in order to locate the ‘Button2’ button available at http://omayo.blogspot.com/ , we can use the below Absolute XPath Expression:

/html[1]/body[1]/div[4]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div[1]/div[4]/div[2]/div[1]/aside[1]/div[1]/div[9]/div[1]/button[1]

The above Absolute XPath Expression start from the root element /html and contains the complete path till it reaches the last node /button.

As it contains the entire path, the location of the UI element will be faster when compared to other XPath types.

Disadvantages of Absolute XPath Expressions

The following are the disadvantages of Absolute XPath Expressions:

  • > Due to small changes in the UI, the Absolute XPath Expression of a UI element may change and won’t work.

Let me explain this with a practical example:

Let’s make a small change in the UI, by moving the ‘Button2’ button from the left side of the page to the right side of the page. After making the above change, let’s see whether the Original Absolute XPath Expression captured when the button on the left side of the page is still working after moving the button to the right side of the page.

Absolute XPath Expressions - Example

 

Follow the below practical steps to check the above:

1) Open http://omayo.blogspot.com/ and scroll down to view the ‘Button2’ button which is on the right side of the application as shown below:

Absolute XPath Expressions - Left Side Button

 

 

 

 

 

 

2) Right click on the ‘Button2’ button, select ‘Inspect’ option

Absolute XPath Expressions - Inspect

 

 

 

 

 

 

 

 

 

3) Select the ‘Elements’ tab in the Chrome Developer option and then find & select ‘ChroPath’ option as shown below:

Absolute XPath Expressions - ChroPath

 

4) Copy the Absolute XPath Expression of the above ‘Button2’ button on the left side of the page by selecting the ‘Copy’ option as shown below:

Absolute XPath Expressions - Copy Left Absolute XPath

5)  Now open any notepad in your machine and paste the above copied Absolute XPath Expression for the ‘Button2’ button when it is on the left side of the page as shown below:

Absolute XPath Expressions - Pasted Left XPath

 

6) Open Selenium IDE and enter the above Absolute XPath Expression and observe that the Absolute XPath Expression is able to locate the Button2 button.

Absolute XPath Expressions - Locating

 

7) As a developer of the above application, I am moving the ‘Butt0n2’ button from its original place i.e. right side of the page to the left side of the page as shown below:

Note: You cannot move the button to the right side as you are not the owner of http://omayo.blogspot.com/ application. Only I can do it as shown below:

Absolute XPath Expressions - Right Side

 

8) Now copy the original Absolute XPath Expression pasted in Step 5 into a NotePad software and enter it into the Selenium IDE and observe that it no more locates the Button2 button for just moving it to the right side of the page

Hence the major disadvantage of Absolute XPath Expression is that it won’t locate the UI elements for just making small changes in the UI.

Let’s find out the reason for behind it, by following the below steps:

9) After moving the ‘Button2’ button to the right side of the page, let’s check whether there is any change in the Absolute XPath Expression. Right click on the ‘Button2’ button which is moved to the right side of the page, select ‘Inspect’ option as shown below:

Absolute XPath Expressions - Right Inspect

 

10) Copy the Absolute XPath Expression of the above ‘Button2’ button on the right side of the page by selecting the ‘Copy’ option as shown below:

Absolute XPath Expressions - Right Side Button Copy XPath

 

11) Paste the above copied Absolute XPath Expression for the ‘Button2’ button when it is on the right side of the page as shown below:

Absolute XPath Expressions - Right Side Paste

 

12) Now compare the Absolute XPath Expressions of the ‘Button2’ button when the button is on the left side and right side of the page as shown below:

Absolute XPath Expressions - Changes

 

Observe that just for moving the UI Button ‘Button2’ on the application from the left side of the page to right side of the page, the above changes in the Absolute XPath Expression happened and hence the old Absolute XPath Expression is unable to locate the button on moving it to the right side.

Hence this is the major disadvantage in Absolute XPath Expressions as they change for simple UI changes on the Web Pages.

Hope you understood the advantages and disadvantages of Absolute XPath Expressions in this article.

In the next article, I will practically demonstrate the next XPath Expression type i.e. relative XPath Expressions in details

Next Steps:

  • > To learn more about Selenium, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning 🙂

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

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