XPath Starts-With(): Enhance your skills by practicing XPath Starts-With() syntax with our given sample HTML codes and interactive exercises, designed to help you master selecting elements in HTML and XML documents.

Boost Your Skills: Practice XPath Starts-With() Syntax with easy Exercises.


Home->Practice 4

  Next Exercise >>
Please Follow Step 1: Read XPath Question >>Step 2: Check HTML Source Code >>Step3: Enter XPath Syntax in O/P Box
XPath Exercise 4

Q1. Find All List Items

Q2. Find Coffee Item

Q3. Find Tea Item

Q4. Find Milk Item

Q5. Find All Headers using starts-with() method

Q5. Find Coffee using starts-with() method

Q5. Find Tea using starts-with() method

Q5. Find Milk using starts-with() method

HTML Source document
         <h1>Heading 1 </h1>
         <h2>Heading 2 </h2>
         <h3>Heading 3 </h3>
         <h4>Heading 4 </h4>
        <h5>Heading 5 </h5>
        <h6>Heading 6 </h6>
        
         <ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul> 
        
        

XPath O/P Box

Enter XPath Syntax here:   

XPath Tips and Syntax For This Page Exercise :

Using starts-with()

//HTMLtag[starts-with(@attribute_name,'attribute_value')]
or
//*[starts-with(@attribute_name,'attribute_value')]

Example:
// Navigate to a website
driver.get("https://www.example.com");
// Select all elements whose class attribute starts with "example-"
List elements = driver.findElements(By.xpath("//*[starts-with(@class, 'example-')]"));

Using Double Slash

Syntax : //tagname

Where tagname is the name of the HTML element you want to search for.

Here are a few examples to demonstrate how to use the double slash in XPath:

e.g :
1) //p
2) //ul/li
We would love to hear your thoughts, suggestions, concerns or problems with anything so we can improve. Request you to please use Social Media button in Right Side for this website growth.