Updated March 28, 2023
Definition of XPath Multiple Conditions
XPath multiple conditions are used to select multiple attributes, by using XPath in multiple conditions we can select any category with the attribute by specifying child node. We can define the condition in the path when we have to forward the message to more than one interface or more than one receiver. XPath multiple conditions is selecting the incoming messages while reaching the server with multiple receivers or interfaces.
Overview of XPath Multiple Conditions
- As we know that selenium is a free and open-source framework of web automation that was used to test the application across different browsers and platforms.
- To implement the framework by using multiple conditions first we need to locate the web element.
- In multiple conditions we can use to ways for matching the expression for one value is matching and the second value is executing.
- We can use the call processing rule at the time of working with multiple conditions for setting the variable to skip the backside. We can also use the action of transform to send the default response back to the client by using multiple conditions.
- We can use below syntax to use multiple conditions are as follows.
Syntax:
//quotes/category [@aattribute1 = val1 and attribute2 = val2]
//quotes/category [@aattribute1 = val1 and attribute2 = val2]
- In above syntax quotes or category will defines as which category we are using with multiple conditions. It is very important parameter while using multiple conditions.
- Attribute1 and attribute2 is defines the number of attributes which was we are using with multiple conditions; we can use the multiple conditions by defining the multiple attributes.
- Value1 and value2 are defined as the value which we have defined in multiple conditions. We can use multiple values as per multiple conditions which are used in multiple conditions. XPath multiple conditions are very important and useful to define the multiple conditions.
How to use XPath multiple conditions?
- We are using OR and AND conditions at the time of using the XPath multiple conditions are as follows.
- The below steps show how to use XPath multiple conditions are as follows. We are creating the project name as XPathMultipleConditions. In the below step, we are creating the project template of XPath multiple conditions in spring boot.
1. At the time of creating the project we are providing project group name as com.example, artifact name as XPathMultipleConditions, project name as XPathMultipleConditions, and selected java version as 11. We are defining the version of spring boot as 2.6.7.
Group – com.example
Artifact name – XPathMultipleConditions
Name – XPathMultipleConditions
Spring boot – 2.6.7
Project – Maven
Java – 11
Package name – com.example. XPathMultipleConditions
Project Description – Project for XPathMultipleConditions
Dependencies – Spring web
Packaging – Jar
2. In this step, we are extracting the downloaded project and opening the same by using the spring tool suite as follows.
3. In this step, we are checking all the project structures and its files are as follows. Also, we are checking whether 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. In this step we are adding dependency in multiple conditions We are adding dependency are as follows.
Code –
<dependency>
<groupId> net.sf.saxon </groupId>
<artifactId> saxon-XPath </artifactId>
<version> 8.7 </version>
</dependency>
5. Now we are creating student.html by defining the multiple conditions by using AND condition are as follows. In the 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" and @stud_no = "1"] </td>
</tr>
<tr>
<td> Stud2 : </td>
<td> input[@type = "checkbox" and @stud_name="PQR" and class = "4th"] </td>
</tr>
<tr>
<td> Stud3 : </td>
<td> input[@type="text" and stud_name="XYZ" and stud_no = "2"] </td>
</tr>
<tr>
<td> Stud4 : </td>
<td> input [@type = "checkbox" and name = "CBD" and stud_no = "3"] </td>
</tr>
<tr>
<td> Stud5 : </td>
<td> input[@type="password" and class = "password" and stud_no = "4"] </td>
</tr>
</table>
</body>
</html>
XPath Multiple Conditions Values
- In XPath expression single attribute will identify the multiple conditions then we can use more than one attribute in the expression of the path for locating a single element. For writing multiple conditions we can apply the AND and OR conditions.
- In below example we are using multiple values with by using multiple OR condition are 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" OR emp_no = "101"] </td>
</tr>
<tr>
<td> Emp2 : </td>
<td> input[@type = "checkbox" OR @Emp_name="PQR" OR emp_no = "102"] </td>
</tr>
<tr>
<td> Emp3 : </td>
<td> input[@type="text" OR Emp_name="XYZ" OR emp_no = "103"] </td>
</tr>
<tr>
<td> Emp4 : </td>
<td> input [@type = "checkbox" OR Emp_name = "CBD" OR emp_no = "104"] </td>
</tr>
<tr>
<td> Emp5 : </td>
<td> input[@type="password" OR emp_name = "XYA" OR emp_no = "105"] </td>
</tr>
</table>
</body>
</html>
XPath multiple conditions-xml
- We are using multiple conditions with xml. Below is the example of multiple conditions as follows. We are creating xml file name as stud.xml as follows.
- In below example we can see that we have used student and school tag to define the multiple conditions in xml.
Code –
<?xml version = "1.0" encoding = "utf-8"?>
<students>
<school name = "International school">
<stud> ABC <student no = "1" > Quote One </student> <student no = "2" > Quote nine </student> </stud>
</school>
<school name = "International school">
<stud> PQR
<student no = "3" > Quote two </student> </stud>
</school>
</students>
Conclusion
We can use the call processing rule at the time of working with multiple conditions for setting the variable to skip the backside. They are used to select multiple attributes, by using XPath in multiple conditions we can select any category with an attribute by specifying child node.
Recommended Articles
This is a guide to XPath Multiple Conditions. Here we discuss the Definition, How to use XPath multiple conditions, and examples with code implementation respectively. You may also have a look at the following articles to learn more –