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 |
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
<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: // Navigate to a website driver.get("https://www.example.com"); // Select all elements whose class attribute starts with "example-" Listelements = 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