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 First Element
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 First Element

XPath First Element

Definition of XPath First Element

XPath first element is used to locate the first element from the specified string. It is the predefined method of the language of XPath that is used in a statement of XPath for locating the node of the first element from the node type. Basically, the first element method in XPath will select the first element out of the all element which was present in a string for the first element of XPath.

What is the XPath first element?

  • First element is returning the position of the first element from the current context. Sometimes we need to find which element is coming to first and which was next, for finding the first element from the set we are using XPath first element.
  • First element is very important for defining the template for the first occurrence for the given element or it is also useful for testing a given node from the first in a set of nodes to which it belongs.
  • The first element will be returning a number from size as per the context evaluation of the expression.
  • We can find the first element by using the following different ways are as follows.
  • Find the first element by name.
  • Find the first element by id.
  • Find the first element by class name.
  • Find the first element by XPath.
  • Find the first element by link text.
  • Find the first element by CSS selector.
  • Find the first element by tag name.
  • Find the first element by partial link text.
  • In order to get the first element of an ID or name of an element, we can use the XPath to display the first value of an element.

How to XPath the first element?

  • The below steps show how we can XPath the first element are as follows. We are creating the project name as XPathFirstElement. In the below step we are creating the project template of first element in spring boot.
  1. At the time of creating the project we are providing project group name as com. example, artifact name as XPathFirstElement, project name as XPathFirstElement, and selected java version as 11. We are defining the version of spring boot as 2.6.7.

Group – com.example

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)

Artifact name – XPathFirstElement

Name – XPathFirstElement

Spring boot – 2.6.7

Project – Maven

Java – 11

Package name – com.example. XPathFirstElement

Project Description – Project for XPathFirstElement

Dependencies – Spring web

Packaging – Jar

1-1

2. In this step we are extracting the downloaded project and opening the same by using the spring tool suite as follows.

1-2

3. In this step we are checking all the project structures and their files are as follows. Also, we are checking the pom.xml file is created or not. Suppose this file is not created then we need to create the same manually. In the below example this file is created, so we have no need to create it manually.

4

4. In this step we are adding a dependency in the first element project. We are adding dependencies as follows.

Code –

<dependency>
<groupId> net.sf.saxon </groupId>
<artifactId> saxon-XPath </artifactId>
<version> 8.7 </version>
</dependency>

5

5. Below is the view of first element from the element array finder. It will not retrieving the underlying element.

Code –

<ul class = "letter">
<li> A </li>
<li> B </li>
<li> C </li>
<li> D </li>
<li> E </li>
<li> F </li>
<li> G </li>
<li> H </li>
<li> I </li>
<li> J </li>
<li> K </li>
<li> L </li>
<li> M </li>
<li> N </li>
<li> O </li>
<li> P </li>
<li> Q </li>
<li> S </li>
<li> T </li>
<li> U </li>
<li> V </li>
<li> W </li>
<li> X </li>
<li> Y </li>
<li> Z </li>
</ul>

6

6. Below is the code of XPath first element from the element array finder.

Code –

public class FirstElement {
let elefirst = element.all (by.css('.items li')).first();
expect (elefirst.getText ()).toBe ('First')
}

XPath First Element 7

XPath First Element 8

Enable XPath selection

  • Google chrome provides the debugging tool which was built called chrome dev tools. It will include many handy features which were used to evaluate the CSS selector’s without any extensions of third-party tools.
  • We can also execute the token from the console panel which was used to validate and evaluate the same.
  • In the below example we are enabling the XPath selection as follows. We are enabling the selection in the following example.

XPath First Element 9

  • XPath uses the expression of the path for selecting a node in the xml document. Nodes are selected by using the following path. Below is the most useful expression of XPath selection as follows.
  • Nodename – It will select all the nodes with the name as node name.
  • / – This is used to select from the root node.
  • // – This symbol is used to select the nodes from the current node which will match the selection
  • . – This is used to select the current node.
  • @- It is used to select the attribute.
  • We can use the search function inside the elements panel for evaluating the CSS selector’s XPath and also we can highlight the matching rows from the DOM.

XPath First Element Array

  • XPath first element array can be nested, we can say that members of an array can be attribute values including the sequences, function, maps and other values. The array member contains a sequence that is empty.
  • The first element of an array contains a single item, so it contains the sequence of an array.
  • As per sequence, the members of an array are addressed by using an integer in the range of 1 to N.
  • XPath’s first element array is XDM values which are immutable. At the time of appending, removing an entry from an array we will get a new array.
  • By using the sequence and maps first element array doesn’t have an intrinsic type in an element array.
  • Below is the example.

Code –

(/Students/stud[@name='PQR'])[1]

XPath First Element 10

Conclusion

The XPath first element is returning the position of first element from the current context. XPath first element is the predefined method of language of XPath is used in a statement of XPath for locating the node of first element from the node type.

Recommended Articles

This is a guide to XPath First Element. Here we discuss the Definition, What is the XPath first element, How to XPath the first element , examples with code implementation respectively. You may also have a look at the following articles to learn more –

  1. XPath finder
  2. XPath class
  3. XPath attribute
  4. XPath text
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