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,
is the id locator in below html code:
2. NAME (name) Locator: Select the first element with the specified @name attribute.
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
<input type="text" name="name" id="name" />
2. NAME (name) Locator: Select the first element with the specified @name attribute.
For example,
is the name locator in below html code:
3. CSS (cssSelectorSyntax) Locator: Select the element using css selectors.
For example,
is the css locator in below html code:
4. Xpath (xpathExpression) Locator: Locate an element using an XPath expression.
For example,
is the xpath locator of “link22” element in below html code:
5. DOM (javascriptExpression) Locator: Find an element using JavaScript traversal of the HTML Document Object Model. DOM locators must begin with "document.".
For example,
is the dom locator in below html code:
Click here to read more about the locators in selenium.
name=name
<input type="text" name="name" id="name" />
3. CSS (cssSelectorSyntax) Locator: Select the element using css selectors.
For example,
css=a[href="#id3"]
<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]
<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
<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.
0 Comments
What would you like to add in my list? I look forward to reading your comments below.