Locators in selenium
Posted By : Aarushi Sharma | 25-Sep-2017
Different types of locators in Selenium IDE
1)Id->It is the most common way of locating element because ID's are unique for each element.
Format->id=id of element
eg->driver.findElement(By.id("id of the element"));
2)Name->It
Format->name=name of the element
eg->driver.findElement(By.name("name of the element"));
3)Link Text->This locator is only applied on hyperlink text.
Format->link=link_text
eg->driver.findElement(By.linktext("link of the element"));
4)CSS Selector->Css selector are used to identify the element using the combination of HTML tag,id,class and attribute.
1)Tag and ID
Fomat->css=tag#id
tag=HTML tag of the element
#=this is used when using
id=Id of element being clicked
eg->driver.findElement(By.cssSelector("tag of element# id of element"));
2)Tag and Class
Format->css=tag.class
.=this is used when using class with
class=class of element being accessed
eg->driver.findElement("tag of the element.class of the element"));
3)Tag and Attribute
Format->css=tag[attribute=value]
[]=square bracket within which a specific attribute with
attribute=Always used attribute which is unique for the elementeg->ID
value=value of the
eg->driver.findElement(By.cssSelector("tag of the element[attribute=value]);
4)Tag
Format->css=tag.class[attribute=value]
5)Xpath->Locating any element using xpath expression.It access any element ,even those who didn't have name,id,class.
eg->driver.findElement(By.xpath("xpath string"));
6)ClassName->Locating a element using class name
eg->driver.findElement(By.classname("classname of the element"));
7)Locating By DOM->
1)getElement by ID->This method can access one element at a time ,and that is the element whose id is specified.
Format->getElementById()
2)getElement by Name->This method give the collection of element whose elements are same.
Format->document.getElementsByname("name")[index]
name-name of the element which has to be accessed
index->it is the integer which specified which element has to be used.
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Aarushi Sharma
Aarushi is a bright QA engineer with experience in manual testing. Apart from that she loves to dance.