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 Multiple Attributes
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 Multiple Attributes

XPath Multiple Attributes

Definition of XPath Multiple Attributes

XPath multiple attributes are written by using the web element, as per the situation we can use multiple attributes, or also we can use the single attribute for finding the web page element. While using the single attribute on XPath expression it will return the matching element then we can use the single attribute only. XPath multiple attributes are very important and useful in XPath to retrieve multiple elements.

Overviews XPath Multiple Attributes

In some cases, using the single attribute in the expression of XPath will return the multiple matching elements on the web page. After returning the multiple-element on the web page we can use the multiple attributes in the expression of XPath till we get the matching element. To determine the element we can take the help of an attribute within the tag of html or we can also use the attribute combination and the values for identifying the element. Suppose the id attribute is not present then we can use the other attribute like class and name.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

How XPath multiple attributes work?

  • At the time of working XPath multiple attributes, we can use two or more attributes in a single class. We can utilize the distinct attribute available for only the tag or attribute combination and values for identifying the element, for the same we need to use the XPath multiple expression.
  • If the XPath expression in a single attribute identifies the multiple elements, then we can use more than one attribute in the expression of the path for locating a single element.
  • For writing multiple attributes, we can apply the AND and OR conditions. Below is the syntax of multiple attributes by using AND conditions are as follows.

Syntax –

Name_of_tag [@name_of_attribute1 = 'val1' AND @name_of_attribute2 = 'val2']
  • Below is the syntax of multiple attributes by using OR conditions are as follows.

Syntax –

Name_of_tag [@name_of_attribute1 = 'val1' OR @name_of_attribute2 = 'val2']
  • In the above syntax, the tag name specifies the name of the tag which we have defined in multiple attributes.
  • Name of the attribute is defining the attribute name which we are using in multiple attributes, we can use multiple attributes in a single line code.
  • Value is defining the value which we are using in the XPath attribute, we can use multiple values as per attribute in a single line code.
  • We are using OR and AND conditions at the time of defining the XPath multiple attributes.
  • The below steps show how we can work with multiple attributes as follows. We are creating the project name as XPathMultipleAttributes. In the below step we are creating the project template of multiple attributes in spring boot.

1. At the time of creating the project we are providing project group name as com.example, artifact name as XPathMultipleAttributes, project name as XPathMultipleAttributes, and selected java version as 11. We are defining the version of spring boot as 2.6.7.                          

Group – com.example

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 – XPathMultipleAttributes

Name – XPathMultipleAttributes

Spring boot – 2.6.7

Project – Maven

Java – 11

Package name – com.example. XPathMultipleAttributes

Project Description – Project for XPathMultipleAttributes

Dependencies – Spring web

Packaging – Jar

wer

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

3456

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.

vdfg

4. In this step we are adding a dependency in multiple attributes We are adding dependency as follows.

Code –

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

lkjhg

5. Now we are creating stud.xml by defining the multiple attribute by using AND condition are as follows. In below example also we are running the project.

Code –

<html>
</head>
<body>
<table align = "center" width = 80% cellspacing = "2" cellpadding = "2" >
<tr>
<td> Stud1 : </td>
<td> input[@type = "text" and @stud_name="ABC"] </td>
</tr>
<tr>
<td> Stud2 : </td>
<td> input[@type = "checkbox" and @name="PQR" class = "4th"] </td>
</tr>
<tr>
<td> Stud3 : </td>
<td> input[@type="text" and name="XYZ"] </td>
</tr>
<tr>
<td> Stud4 : </td>
<td> input [@type = "checkbox" and name = "CBD"] </td>
</tr>
<tr>
<td> Stud5 : </td>
<td> input[@type="password" and class = "password"] </td>
</tr>
</table>
</body>
</html>

msa

cxz

XPath multiple attributes Examples

  • Below is the example of multiple attributes as follows. In the below example we are using the OR condition as follows.

Code –

<html>
</head>
<body>
<table align = "center" width = 90% cellspacing = "2" cellpadding = "2" >
<tr>
<td> Emp1 : </td>
<td> input[@type = "text" OR @Emp_name="ABC"] </td>
</tr>
<tr>
<td> Emp2 : </td>
<td> input[@type = "checkbox" OR @Emp_name="PQR" class = "4th"] </td>
</tr>
<tr>
<td> Emp3 : </td>
<td> input[@type="text" OR Emp_name="XYZ"] </td>
</tr>
<tr>
<td> Emp4 : </td>
<td> input [@type = "checkbox" OR Emp_name = "CBD"] </td>
</tr>
<tr>
<td> Emp5 : </td>
<td> input[@type="password" OR class = "password"] </td>
</tr>
</table>
</body>
</html>

1235698

XPath Multiple Attributes 14789

  • Below is the example of XPath multiple attributes as follows. In the below example we are using the AND condition as follows.

Code –

<html>
</head>
<body>
<table align = "center" width = 90% cellspacing = "2" cellpadding = "2" >
<tr>
<td> Emp1 : </td>
<td> input[@type = "text" AND @Emp_name="ABC"] </td>
</tr>
<tr>
<td> Emp2 : </td>
<td> input[@type = "checkbox" AND @Emp_name="PQR" class = "4th"] </td>
</tr>
<tr>
<td> Emp3 : </td>
<td> input[@type="text" AND Emp_name="XYZ"] </td>
</tr>
<tr>
<td> Emp4 : </td>
<td> input [@type = "checkbox" AND Emp_name = "CBD"] </td>
</tr>
<tr>
<td> Emp5 : </td>
<td> input[@type="password" AND class = "password"] </td>
</tr>
</table>
</body>
</html>

XPath Multiple Attributes qwertyui

XPath Multiple Attributes 45786321

Conclusion

Returning to the multiple-element on the web page we use the multiple attributes in the expression of XPath till we get the matching element. XPath multiple attributes are written by using a web element, as per the situation we can use multiple attributes or a single attribute for finding the web page element.

Recommended Articles

This is a guide to XPath Multiple Attributes. Here we discuss the Definition, overviews, How to work XPath multiple attributes, and 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