Home->Practice 2 |
Next Exercise >> | |
---|---|---|
Please Follow Step 1: Read XPath Question >> | Step 2: Check HTML Source Code >> | Step3: Enter XPath Syntax in O/P Box |
Q7. Find Heading 1 using "Contains() function"
Q8. Find Heading 2 using "Contains() function"
Q9. Find Heading 3 using "Contains() function"
Q10. Find Heading 4 using "Contains() function"
<h1>Heading 1 </h1> <h2>Heading 2 </h2> <h3>Heading 3 </h3> <h4>Heading 4 </h4> <h5>Heading 5 </h5> <h6>Heading 6 </h6>
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) //form/div[1]/div/div[1]/div/div/input[1]
Using Contains()
//HTML tag[contains(@attribute_name,'attribute_value')] or //*[contains(@attribute_name,'attribute_value')]
Here are a few examples to demonstrate how to use the Contains() in Selenium:
WebDriver driver = new FirefoxDriver(); driver.get("http://www.example.com"); WebElement link = driver.findElement(By.xpath("//a[contains(text(), 'Link Text')]")); link.click();