EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

XPath starts-with

Secondary Sidebar
XML Tutorial
  • 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
    • 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
Home Software Development Software Development Tutorials XML Tutorial XPath starts-with

Introduction to XPath starts-with

XPath starts-with method is used to check the starting text of an attribute, and it also finds from which element attribute will change dynamically when we refresh the page. Axes of XPath are named because they tell us about the axis element. This method is used to find the element in which attribute values are changed as per a refresh of the web page. This method is beneficial in XPath.

XPath starts-with

Overview of XPath starts-with

The XPath starts-with method will check the starting text of our attribute and find the element which will change dynamically. We use the starts-with method to find the element whose attribute will dynamically change.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Below is the syntax of the XPath starts-with method as follows:

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,064 ratings)

Syntax:

XPath: //name_of_tag [starts-with (@attribute, ‘attribute_value’)]

XPath starts with the method checking whether the first string will start at the time of the second string and return the true or false value. In the above example, the name of the tag is nothing but the tag name we have defined in XPath starts-with method. We are using the name of the tag before the starts-with method. While using this method, we need to use the attribute name and attribute value parameter.

It is used to identify the element when we are familiar with the value of an attribute for a component that starts from the specified text. It will contain the elements of the dynamic web, and those elements of the webpage attribute change dynamically or are refreshed. The method was commonly used in XPath axes for a webdriver of selenium, parent sibling and child, etc. It is used to find elements based on the element’s relationship and per the elements’ document. We use multiple ways to handle complex and dynamic elements. We can use this method to handle the dynamic elements in selenium.

How to Use XPath starts with?

In the below example, we are creating the project of XPathStartsWith:

In the below example, we are making a template of the project name as XPath starts with spring boot.

1. While creating the project into the XPath starts-with using spring boot, we provide the group’s name as com.example, artifact name as XPathStartsWith, project name as XPathStartsWith, and selected java version as 11.

Group – com.example
Artifact name – XPathStartsWith
Name – XPathStartsWith
Spring boot – 2.6.7
Project – Maven
Java – 11
Package name – com.example. XPathStartsWith
Project Description – Project for XPathStartsWith
Dependencies – Spring web
Packaging – Jar

XPath starts-with using spring boot

2. In the figure below, we can extract the project name as XPathStartsWith and open this project using the spring tool suite.

extract the project name as XPathStartsWith

3. In the below step, we are checking the structure of the XPath starts-with project. Also, we are seeing the project dependency, which was added to the pom.xml file. Also, we are checking all the structures of the example project.

project dependency

4. Below, we are adding the XPath dependency to the XPathStartsWith project. We need to add the dependency as the tag of dependency.

Code:

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

Output:

add the dependency in as tag of dependency

5. Now, we are creating the file name emp.xml and adding the emp details into it to define the use of XPath starts as follows.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<Employee>
<Emp>
<EmpId> 101 </EmpId>
<Name>
<EmpName> ABC </EmpName>
<Surname> XYZ </Surname>
</Name>
<Addr>
<Emp_addr> Pune </Emp_addr>
</Addr>
<DateOfBirth> 01/02/1995 </DateOfBirth>
</Emp>
<Emp>
<EmpId> 102 </EmpId>
<Name>
<EmpName> PQR </EmpName>
<Surname> CBD </Surname>
</Name>
<Addr>
<Emp_addr> Mumbai </Emp_addr>
</Addr>
<DateOfBirth> 01/02/1993 </DateOfBirth>
</Emp>
</Employee>

Output:

creating the file name emp.xml

6. After creating the xml file, we need to create a java file. We are adding the below code into the java file as follows.

Code:

public class startswith
{
  public static void main(String[] args)
{
WebServer XPathdriver = new FirefoxDriver ();
XPathdriver.manage ().window ().maximize();
String URL = "example.com";
XPathdriver.get (URL);
XPathdriver.manage ().timeouts ().implicitlyWait (15, TimeUnit.SECONDS);
WebElement searchBox = XPathdriver.findElement (By.XPath ("//input[starts-with(@name, 'keyword')]"));
searchBox.sendKeys ("Selenium WebDriver");
button = XPathdriver.findElement(By.XPath("//button[starts-with(@type,'submit')]"));
button.click ();
XPathdriver.close ();
System.out.println ("XPath starts-with");
   }
}

Output:

we need to create java file

XPath starts-with 8

XPath starts-with Function

To load the parse xml document using Microsoft xml is a general requirement in a document object model for identifying attribute elements whose value starts with a sequence of characters or a specific character. To define the XPath starts with function first; we create the xml document name as stud.xml as follows.

In the below example, we are defining the student information to show the example of the starts-with function.

Code:

<?xml version="1.0" encoding="UTF-8"?>
<Student>
  <Stud>
  <StudId> 101 </StudId>
  <Name>
  <StudName> ABC </StudName>
  <Surname> XYZ </Surname>
  </Name>
  <Addr>
  <Stud_addr> Pune </Stud_addr> </Addr>
  <DateOfBirth> 01/02/2014 </DateOfBirth>
  </Stud>
  <Stud>
  <StudId> 102 </StudId>
  <Name>
  <StudName> PQR </StudName>
  <Surname> CBD </Surname>
  </Name>
  <Addr>
  <Stud_addr> Mumbai </Stud_addr>
  </Addr>
  <DateOfBirth> 01/02/2013 </DateOfBirth>
  </Stud>
</Student>

Output:

defining the student information

Then we opened the preceding code, loading the xml from the stud.xml files. It will execute the XPath query, which uses the starts-with XPath function for identifying all students whose first names will start with the A letter. We can also initiate for loop on to the selected nodes and display the first names. The function’s first parameter specifies the source or the string node, which comparison needs to be executed.

The second parameter of the XPath starts-with function is the string pattern which specifies the sequence of characters used in a comparison. In function, it is essential to remember the string pattern supplied in a second parameter with the function name as starts-with. We can run our project by using the following way. The below example shows to run the example of the starts-with function.

example of the starts-with function

Conclusion

The XPath starts-with method will check the starting text of our attribute and find the element which attribute will change dynamically. The method is used to check the starting text of an attribute, and it also finds from which element attribute will change dynamically when we refresh the page.

Recommended Articles

This is a guide to XPath starts-with. Here we discuss the introduction, function, and how to use XPath starts-with. You may also have a look at the following articles to learn more –

  1. XPath Sibling
  2. XPath Ancestor
  3. XPath regex
  4. XPath namespace
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

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More