Google+

335. contains( ) - XPath function






contains( ) is one of the predefined methods of XPath Language which is used in XPath Statement to locate the element node containing specified text on the page or to locate the element node containing specific text in its attribute value.

Lets Implement This:

1. Open http://compendiumdev.co.uk/selenium/basic_web_page.html
2. Observe that there are two paragraph texts on the page as shown below:


3.. Right click on the Page and select 'View Page Source' option as shown below:


4. Ensure that HTML Source code of the page is displayed as shown below:




5. View the HTML Source code in the above step and lets locate the paragraph texts on the page containing 'Another' text by following the below steps.


6.  Open http://compendiumdev.co.uk/selenium/basic_web_page.html  in Firefox Browser
7.  Click on 'FireBug' Add-On option
8.  Select the 'Firepath' tab from the displayed 'FireBug' options
9. Type Relative XPath path  //p[contains(.,'Another')] into the XPath field and click on 'Eval' button as shown below:


10. Observe that the paragraph text containing 'Another' text got high lighted on the page as shown below:


So we've located the paragraph text on the page containing 'Another' text using XPath statement. Now lets move forward and locate the paragraph text that contains '1' text in its id attribute value by following the below steps.

11. Type Relative XPath path  //p[contains(@id,'1')] into the XPath field and click on 'Eval' button as shown below:


12. Observe that the paragraph text containing '1' text in the id attribute value of <p> tag of HTML source code got high lighted on the page as shown below:






Please comment below to feedback or ask questions.

starts-with( ) XPath Function will be explained in the next post.




No comments: