Monday, January 27, 2014

XPATH LOCATOR’S EXAMPLE IN SELENIUM

We have already learned about Xpath locator in previous posts.

Following are different example of Xpath locator:


  1. <div class="MsoListParagraphCxSpFirst">  
  2. <table id="table1"><o:p></o:p></div>  
  3. <div class="MsoListParagraphCxSpMiddle">  
  4. <form method="POST"  
  5. action="#"><o:p></o:p></div>  
  6. <div class="MsoListParagraphCxSpMiddle">  
  7. <tbody><o:p></o:p></div>  
  8. <div class="MsoListParagraphCxSpMiddle">  
  9. <tr><td>Name: </td><td><input  
  10. type="text" id="name" size="20"></td></tr><o:p></o:p></div>  
  11. <div class="MsoListParagraphCxSpMiddle">  
  12. <tr><td>Email Address: </td><td><input  
  13. type="text" name="email" size="20"></td></tr><o:p></o:p></div>  
  14. <div class="MsoListParagraphCxSpMiddle">  
  15. <tr><td><input  
  16. type="submit" value="Submit"  
  17. class="button"></td></tr><o:p></o:p></div>  
  18. <div class="MsoListParagraphCxSpLast">  
  19. </tbody><o:p></o:p></div>  
  20. </table>  

Xpath Locator based on id of element:
For example,
  1. xpath=//input[@id='name']  
is the xpath based on id for Name textbox in above html code.

Xpath Locator based on name of element: 
For example,
  1. xpath=//input[@name='email']  
is the xpath based on name for Email Address textbox in above html code.

Xpath Locator based on class of element: 
For example,
  1. xpath=//input[@class='button']  
is the xpath based on class for Submit button in above html code.

Xpath Locator based on value of element: 
For example,
  1. xpath=//input[@value='Submit ']  
is the xpath based on value for Submit button in above html code.

Xpath Locator based on containing text by element: 
For example,
  1. xpath=//p[contains(text(),'Name')]  
is the xpath based containing text for Name label in below html code.

No comments:

Post a Comment