XPath Contains(): Enhance your skills by practicing XPath Contains() 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 Contains() Syntax with easy Exercises.


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
XPath Exercise 2

Q1. Find Heading 1

Q2. Find Heading 2

Q3. Find Heading 3

Q4. Find Heading 4

Q5. Find Heading 5

Q6. Find Heading 6

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"

Q11. Find Heading 5 using "Contains() function"

Q12. Find Heading 6 using "Contains() function"

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> 
        

XPath O/P Box

Enter XPath Syntax here:   

Tips and Syntax For This Page Xpath Exercise :

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();

In this example, the contains function is used to match a link whose text contains the string "Link Text". The resulting WebElement is then clicked, which simulates a user clicking the link on the page.

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.