EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials XML Tutorial XPath Position
Secondary Sidebar
XML Tutorial
  • Xpath
    • What is XPath?
    • XPath namespace
    • XPath for JSON
    • XPath Last Element
    • Xpath Substring
    • XPath First Element
    • XPath local-name
    • XPath Multiple Attributes
    • XPath Matches
    • XPath Position
    • XPath Index
    • XPath regex
    • XPath id contains
    • XPath innertext
    • XPath Multiple Conditions
    • XPath Helper
    • XPath Generator
    • XPath ID
    • XPath Locator
  • Basic
    • What is XML?
    • XML Tags
    • XML URL
    • XPath Sibling
    • XML root element
    • XML Encryption
    • XML Parsing php
    • xml parsing with java
    • Dataset XML
    • XML Parser in C#
    • XML Tree
    • XML boolean
    • XML sitemap
    • XML Array
    • XML reserved characters
    • XML Viewer
    • XML Uses
    • XML Special Characters
    • XML generator
    • XML file format
    • XML DOM
    • XML ampersand
    • XML Mapping
    • XML File
    • XML Element
    • XML HttpRequest
    • XML XSD
    • XML Schema
    • XML Namespaces
    • XML Comments
    • XML Attributes
    • XML Encoding
    • XML Validation
    • XML CDATA
    • XML Database
    • XML Technologies
    • XML Error
    • XML DTD
    • XML Date
    • XML Parsers
    • String in XML
    • XML with CSS
    • XML Versions
    • XML Features
    • XML Commands
    • Servlet web.xml
    • XPath Injection
    • XPath Functions
    • XPath starts-with
    • XPath Selector
    • XPath Count
    • XPath XML
    • XML Parsing in Oracle
    • XML parsing in python

XPath Position

XPath Position

Definition of XPath Position

The position is the most predefined method in XPath language which is used to set or trace the element node at the correct position of the given node type. It is used to execute the integer that represents the ordinal position of the context. Here the position initiates at one which is set as the first node from the given node-set and increased till it reaches the value of the last function. In this article, the definition of XPath position, usage, and examples are discussed in brief.

What is XPath’s position?

If there are number n child tags that are present under the parent tag which is used to place the child tag in the appropriate position with the other child tag, to implement this position() function is used in XPath. It is used in a function that executes the integer that fixes the node-set of context. The position initiates the node-set for the first context and increases to the value that has the last function.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,883 ratings)

How to use the XPath position function?

The root element of an XML document and a simple XPath position and syntax is discussed below.

The supermarket which is the root element has five-element nodes which are applied in the entire descendant:: the axis.

(supermarket: counter, supermarket: kids, Supermarket: groceries, supermarket: veggies, supermarket: clothes)

In the location path, it is defined as follows,

/supermarket : supermarket / descendant :: *

This function sets the node-set values which is composed of five element nodes that helps to locate by adding the predicate like below syntax,

/supermarket : supermarket / descendant :: * [position () = 3]

 It helps to select the third node present in the local node set.

Now the value is passed with the help of the position () function which is applied in both reverse and forward directions from the axis. In the axes, to travel forward type like the prior example, descendant:: the nodes are selected in the given order from the document. If the user tries to access the axis in reverse, he should provide the appropriate negative values to fetch the element from the node. So to frame a location path, the syntax should start at the clothes node and then locate the prior supermarket: counter node.

Here the location path is framed like below,

// clothes/ prior:: * [position ( ) = 3]

To work in the reverse order, the syntax should be represented as prior #1 which fetches the result from the supermarket : clothes and for prior or ancestor #2, it fetches the data from the supermarket: veggies

The position () function is more mandatory for two valid reasons, one is it can be mentioned in any step from the location and the value can be fetched easily and it is not mandatory to travel along with the entire XML document.

// clothes/ prior:: * [position ( ) = 3]

Or // clothes/ prior:: * [3]

The other reason is in many XSLT functions, it is performed for all the nth values present in a few kinds of nodes and then the source tree is transformed.

If the user wants to choose every even row of the table in the document, then all the odd rows should be removed. In other terms, all the alternate rows can be selected. It can be easily achieved using the function position () in the XPath and it works well with numeric operator mod.

XPath position Selenium Locators

The below steps are used in selenium to locate the position () in the function of XPath,

The basic link of selenium should be opened in the default chrome browser where the application chropath should be installed prior. The link to the application is found on the standard selenium website.

In the chrome browser, choose chropath, and there select Rel XPath

2-1

Then Relative expression of XPath should be selected using the //p in the chropath option and the given details are observed from the selected location.

The user can locate the details by using the position () from the function of XPath in the relative expression available in XPath. It can be defined as Relative XPath expression :: // p [position ( ) = 3]

Then as per the syntax, the relative expression in chropath is executed.

Then to locate the next option the same syntax is used but the position values should be changed.

Relative XPath expression :: // p [position ( ) = 2]

2-2

The relative XPath expression is fed in chropath and all the option which is given should be executed.

If already the application chropath is installed and the chrome browser is updated, then the process can be initiated in prompt. The initial input tag is used by applying the relative XPath expression

(// input) [position =1].

XPath Position 2-3

If the number of input tags is used with position () with relative XPath expression.

Then it should be given as relative XPath expression : ( // input ) [position = n]

Execute the above syntax and give the correct tag in place of n to fetch the required data.

In XPath relative expression with greater or lesser than symbol is used when the value between two elements should be compared and fetched. The syntax is below,

// p [ position () > O ]. Here all the p tags are chosen in the HTML and observe that the suitable values are fetched.

XPath Position 2-4

If the user wants to trace all the elements from the local node-set, which is placed between greater than 0 and lesser than 2, it can be executed by defining the function with position ( ) and it can be compared with position () > 2. The syntax to fetch the between values of 0 and 2 are

// p [ position ( ) > 0 and position ( ) < 2 ].

XPath Position 2-5

Conclusion

Hence the selenium locators and usage of XPath position in the document are discussed and the user can be implied to fetch the data easily from the higher dimensional document.

Recommended Articles

This is a guide to XPath Position. Here we discuss the Definition, What is XPath’s position, How to use the XPath position function, and examples with code implementation respectively. You may also have a look at the following articles to learn more –

  1. XPath Descendant
  2. XPath cheat sheet
  3. XPath attribute
  4. XPath Nodes
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more