HomeSelenium

Selenium Locators – Relative XPath Expressions – Part 5

Selenium Locators – Relative XPath Expressions – Part 5

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

In continuation of the previous articles i.e. Relative XPath Expressions – Part 1, Part 2 , Part 3 and Part 4 I am going to explain the next set of Relative XPath Expressions (i.e. Part 5) practically in this article.

Let’s get started.

Selenium Locators – Relative XPath Expression – Part 5

Follow the below steps to practice Relative XPath Expressions on a complex Web Page:

1) Open http://omayo.blogspot.com/ in Chrome Browser, where ChroPath is already installed (Refer ChroPath installation in Chrome Browser here and its usage in Chrome Browser here ) as shown below:

Relative XPath - More complex application

2) Open ‘ChroPath’ functionality as shown below in the Chrome Browser:

Relative XPath - ChroPath

3) Select ‘Rel XPath’ option from the ‘Selectors’ dropdown as shown below:

4) Let’s locate the input tags having the name attribute as ‘gender’ by using the Relative XPath Expression.

In order to locate all the input tags in the web page, we have to use the Relative XPath Expression //input

And, in order to locate all the input tags in the web page having the name attribute value as ‘gender’, we have to use the Relative XPath Expression //input[@name=’gender’]

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating two radio options as shown below:

Selenium Locators - input name gender

5) Let’s locate the first input tag having the name attribute value as gender by using the Relative XPath Expression.

In order to locate all the input tags in the web page, we have to use the Relative XPath Expression //input

And, in order to locate all the input tags in the web page having the name attribute value as ‘gender’, we have to use the Relative XPath Expression //input[@name=’gender’]

And, in order to locate the first input tag in the web page having the name attribute value as ‘gender’, we have to use the Relative XPath Expression //input[@name=’gender’][1]

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating the first radio options as shown below:

Selenium Locators - first input name gender

6) Let’s locate the second input tag having the name attribute value as gender by using the Relative XPath Expression.

In order to locate all the input tags in the web page, we have to use the Relative XPath Expression //input

And, in order to locate all the input tags in the web page having the name attribute value as ‘gender’, we have to use the Relative XPath Expression //input[@name=’gender’]

And, in order to locate the second input tag in the web page having the name attribute value as ‘gender’, we have to use the Relative XPath Expression //input[@name=’gender’][2]

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating the second radio options as shown below:

Selenium Locators - second input name gender

7) Let’s locate all the tags in the web page having the name attribute value as ‘gender’ using the Relative XPath Expression.

In order to locate all the tags in the web page, we have to use the Relative XPath Expression //*

Note: * in the above Relative XPath Expression stands for any tag (it can be input, it can be anchor tags, it can be button tags and other tags)

And, in order to locate all the tags in the web page having the name attribute value as ‘gender’, we have to use the Relative XPath Expression //*[@name=’gender’]

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating two radio options having the name=’gender’ in their HTML code as shown below:

Selenium Locators - Any tag name gender

8) Let’s locate all input tags in the web page having any attribute value as ‘gender’ using the Relative XPath Expression.

In order to locate all input tags in the web page, we have to use the Relative XPath Expression //input

And, in order to locate all input tags in the web page having the any attribute value as ‘gender’, we have to use the Relative XPath Expression //input[@*=’gender’]

Note: * in the above Relative XPath Expression stands for any attribute (it can be id, it can be class, it can be name and other attributes)

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating two radio options having the input tags and value as gender’ for their attributes in their HTML code as shown below:

Selenium Locators - Input Any attribute gender

9) Let’s locate all the tags in the web page having any attribute value as ‘gender’ using the Relative XPath Expression.

In order to locate all the tags in the web page, we have to use the Relative XPath Expression //*

Note: * in the above Relative XPath Expression stands for any tag (it can be input, it can be anchor tags, it can be button tags and other tags)

And, in order to locate all the tags in the web page having any attribute value as ‘gender’, we have to use the Relative XPath Expression //*[@*=’gender’]

Note: * in the above Relative XPath Expression stands for any attribute (it can be id, it can be class, it can be name and other attributes)

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating two radio options as shown below:

Selenium Locators - Any tag Any attribute gender

10) Let’s locate all input tags in the web page having name attribute value as anything using the Relative XPath Expression.

In order to locate all input tags in the web page, we have to use the Relative XPath Expression //input

And, in order to locate all input tags in the web page having name attribute value as anything, we have to use the Relative XPath Expression //input[@name]

Note: In the above Relative XPath Expression, we have not assigned any value to the name attribute. Hence it will locate all the input tags having name attribute available irrespective of their values.

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating 19 elements on the web page having the input tags and name attribute irrespective of their values assigned as shown below:

Selenium Locators - Input Name Any Value

11) Let’s locate all the tags in the web page having any attribute value as anything using the Relative XPath Expression.

In order to locate all the tags in the web page, we have to use the Relative XPath Expression //*

Note: * in the above Relative XPath Expression stands for any tag (it can be input, it can be anchor tags, it can be button tags and other tags)

And, in order to locate all the tags in the web page having any attribute value as anything, we have to use the Relative XPath Expression //*[@*]

Note: * in the above Relative XPath Expression stands for any attribute (it can be id, it can be class, it can be name and other attributes)

Note: In the above Relative XPath Expression, we have not assigned any value to find the elements irrespective of their values assigned to their attributes

Let’s execute the above Relative XPath Expression in ChroPath and observe that it is locating 757 elements (i.e. all elements on the web page) as shown below:

Selenium Locators - All Located

12) Let’s locate all the tags in the web page having id attribute value as radio1 and name attribute value as gender using the Relative XPath Expression.

In order to locate all the tags in the web page, we have to use the Relative XPath Expression //*

Note: * in the above Relative XPath Expression stands for any tag (it can be input, it can be anchor tags, it can be button tags and other tags)

And, in order to locate all the tags in the web page having id attribute value as radio1 and name attribute value as gender, we have to use the Relative XPath Expression //*[@id=’radio1′][@name=’gender’]

Let’s execute the above Relative XPath Expression in ChroPath and observe that one radio option having both id as radio1 and name as gender got located as shown below:

Selenium Locators - One

13) Let’s locate all the tags in the web page having either id attribute value as radio1 or name attribute value as gender using the Relative XPath Expression.

In order to locate all the tags in the web page, we have to use the Relative XPath Expression //*

Note: * in the above Relative XPath Expression stands for any tag (it can be input, it can be anchor tags, it can be button tags and other tags)

And, in order to locate all the tags in the web page having either id attribute value as radio1 or  name attribute value as gender, we have to use the Relative XPath Expression //*[@id=’radio1′ or @name=’gender’]

Let’s execute the above Relative XPath Expression in ChroPath and observe that two radio options (one of them having id as radio1 and other radio option having the name as gender got located) as shown below:

Selenium Locators - OR

Here ends the fifth part of Relative XPath Expressions.

In the next article, I will demonstrate the next set of Relative XPath Expressions in a practical way.

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 *