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