Header Ads

WHICH ARE THE ELEMENT LOCATORS IN SELENIUM?

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" />



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" />




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>



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>

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.


No comments


What would you like to add in my list? I look forward to reading your comments below.



Powered by Blogger.