XPath Practice: Mastering XPath Expressions for Effective Web Automation using Starts-With() Function

Test Your Skills with this Fun and Interactive Game


Home->Practice 4

Next
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 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

XPath O/P

Enter XPath Input 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.