EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Software Development Software Development Tutorials XML Tutorial XPath Multiple Attributes

XPath Multiple Attributes

Updated March 28, 2023

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.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

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.

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

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
MICROSOFT POWER BI Course Bundle - 8 Courses in 1
34+ Hours of HD Videos
8 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
CYBER SECURITY & ETHICAL HACKING Course Bundle - 13 Courses in 1 | 3 Mock Tests
64+ Hours of HD Videos
13 Courses
3 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
62+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
KALI LINUX Course Bundle - 6 Courses in 1
20+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
XPATH Course Bundle - 8 Courses in 1
 32+ Hours of HD Videos
8 Courses
Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • 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

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

Let’s Get Started

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

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

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

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

Forgot Password?

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