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 >>
Step 1: Read XPath Question → Step 2: Check HTML Source Code → Step 3: 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

Q6. Find Coffee using starts-with() method

Q7. Find Tea using starts-with() method

Q8. 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:
driver.get("https://www.example.com");
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.

Examples:

1) //p
2) //ul/li
    
We would love to hear your thoughts, suggestions, concerns or problems with anything so we can improve. Please use the Social Media button on the right side to help this website grow.