What are the main functions of Xpath locator in Selenium?

0 votes
Can someone tell me what are the main functions of Xpath locator in Selenium?
May 9 in Selenium by Danish
12 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hi Danish, for handling complex and dynamic web elements, selenium provides some methods which can be used with Xpath. Following are the Xpath functions which are widely used:

1) Basic Xpath: This function selects nodes or list of nodes on the basis of attributes such as name, class name, id, etc. For eg. Xpath=//input[@id='id1']  or  Xpath=//*[@class='class1'

2) Contains(): It is a method that is used when the value of any attribute changes dynamically e.g. login information. It can locate a web element with the available partial text. For eg. Xpath=.//* [contains (@name, ‘button’)] or Xpath=//*[contains(text (),’sector’)]

3) Using OR & AND: In the case of the OR expression, we use two conditions. Here either 1st condition OR 2nd condition should be true. It is applied when one condition is true or both. It means that at least one condition should be true to find a web element. For eg. Xpath=//*[@type=’submit’ OR @name=’buttonSubmit’]

In the case of the AND expression, we use two conditions. Here both conditions should be true to locate a web element. It will fail to locate an element if any of the conditions are false. For eg. Xpath=//input[@type=’submit’ AND @name=’buttonEnter’]

4) Start-with function: This function is used to find a web element whose value of attribute changes on the refresh or on any dynamic operation on the web page. In this expression, we match the starting text of the attribute that is used to locate an element whose attribute has changed dynamically. For eg. On a web page ID of a particular element changes dynamically such as ‘id1’, ‘id2’, ‘id3’, etc. but the text remains the same. So the Xpath for this element would be: Xpath=//label[starts-with(@id, ‘message’)]

5) Text(): This expression is used with the text function to locate an element with exact text. Following are the examples of text expression. For eg. Xpath=//td

answered May 9 by Anvi
• 5,960 points

Related Questions In Selenium

0 votes
1 answer

What is Xpath and what are the types of it in Selenium Webdriver?

Hi Piyush, XPath is defined as XML path. It is ...READ MORE

answered May 8 in Selenium by Pratibha
• 2,520 points
22 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
3,526 views
0 votes
1 answer

what is the need of xpath when you have attributes like id ,class,name in selenium?

It is not necessary that every element ...READ MORE

answered Jun 1, 2018 in Selenium by Vinita
• 220 points
53 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
74 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
447 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
55 views
0 votes
1 answer

What are the major components of Selenium IDE?

Hi Janvi, Selenium IDE is divided into different ...READ MORE

answered May 13 in Selenium by Anvi
• 5,960 points
8 views
0 votes
1 answer

What are the types of Selenium commands?

Hi Shekhar, Selenium commands are basically classified in ...READ MORE

answered May 13 in Selenium by Anvi
• 5,960 points
8 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.