WHAT SHOULD BE THE LOCATOR PREFERENCE IN SELENIUM AUTOMATION SCRIPTING?

Following should be the locator preference in Selenium automation scripting:
1. ID Locator
2. NAME Locator
3. CSS Locator
4. XPATH Locator
5. DOM Locator




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


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




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

4. Xpath (xpathExpression) Locator: Locate an element using an XPath expression.
For example,
xpath=//table[@id='table1']//tr[2]/td[2]
is the xpath locator of “link22” element in below html code:
<table id="table1">

<tbody>

<tr><td>link11</td><td>link12</td></tr>

<tr><td>link21</td><td>link22</td></tr>

</tbody>

</table>




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

<input type="text" name=" myName " id="myName" />

</form>


Click here to read more about the locators in selenium.



Post a Comment

0 Comments