Monday, January 27, 2014

ELEMENT LOCATORS IN SELENIUM

ID (id) Locator: Select the element with the specified @id attribute.
For example
  1. id=name  
is the id locator in below html code:
  1. <input type="text" name="name" id="name" />  


NAME (name) Locator: Select the first element with the specified @name attribute.
For example,
  1. namename=name  
is the name locator in below html code:
  1. <input type="text" name="name" id="name" />  


CSS (cssSelectorSyntax) Locator: Select the element using css selectors.
For example,
  1. css=a[href="#id3"]  
is the css locator in below html code:
  1. <a href="#id3">Test Link 3</a>  

DOM (javascriptExpression) Locator: Find an element using JavaScript traversal of the HTML Document Object Model. DOM locators must begin with "document.".
For example,
  1. dom=document.forms['myForm'].myName  
is the dom locator in below html code:
  1. <form name="myForm" id="myForm" action="#" method="post">  
  2.   
  3. <input type="text" name=" myName " id="myName" />  
  4.   
  5. </form>  


Xpath (xpathExpression) Locator: Locate an element using an XPath expression.
For example,
  1. xpath=//table[@id='table1']//tr[2]/td[2]  
is the xpath locator of “link22” element in below html code:
  1. <table id="table1">  
  2.   
  3. <tbody>  
  4.   
  5. <tr><td>link11</td><td>link12</td></tr>  
  6.   
  7. <tr><td>link21</td><td>link22</td></tr>  
  8.   
  9. </tbody>  
  10.   
  11. </table>  

No comments:

Post a Comment