Google+

336. starts-with( ) XPath Function






starts-with( ) is one of the predefined methods of XPath Language which is used in XPath Statements to locate the element  starting with the specified text  or to locate the element node containing an attribute value which is starting with the specified text.

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 starting with '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[starts-with(.,'Another')] into the XPath field and click on 'Eval' button as shown below:




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



So we've located the paragraph text on the page starting with  'Another' text using XPath statement. Now lets move forward and locate the paragraph text that starts with 'm' text in its class attribute value by following the below steps.

11. Type Relative XPath path  //p[starts-with(@class,'m')] into the XPath field and click on 'Eval' button as shown below:



12. Observe that the paragraph text starting with 'm' text in the class 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.

Other XPath Functions will be explained in the next post.



No comments: