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, 2019 in Selenium by Danish
1,012 views

1 answer to this question.

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, 2019 by Anvi
• 14,150 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 9, 2019 in Selenium by Pratibha
• 3,690 points
5,364 views
0 votes
1 answer

What are the main disadvantages of using implicit wait in Selenium?

Hey Aaron, the main disadvantage of implicit ...READ MORE

answered Jun 1, 2019 in Selenium by Abha
• 28,140 points
8,424 views
0 votes
1 answer

What are the main types of regex quantifiers used in Selenium Webdriver?

Hi Andrew, some of the regex quantifiers ...READ MORE

answered Jun 26, 2019 in Selenium by Abha
• 28,140 points
5,599 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,500 points
17,418 views
0 votes
2 answers

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,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 views
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,910 points
7,209 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,865 views
0 votes
1 answer

What are the different types of TestNG listeners in Selenium Webdriver?

Hello Jagrati, some of the TestNG listeners ...READ MORE

answered Jun 12, 2019 in Selenium by Anvi
• 14,150 points
1,812 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP