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 select first attribute with the specified name attribute.

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.

Css selector has many formats:

 

1)Tag and ID

Fomat->css=tag#id

tag=HTML tag of the element 

#=this is used when using css selector with ID

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 css selector

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 it's value is places

attribute=Always used attribute which is unique for the elementeg->ID

value=value of the choosen attribute

eg->driver.findElement(By.cssSelector("tag of the element[attribute=value]);

 

4)Tag ,Class and Attribute

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

Related Tags

About Author

Author Image
Aarushi Sharma

Aarushi is a bright QA engineer with experience in manual testing. Apart from that she loves to dance.

Request for Proposal

Name is required

Comment is required

Sending message..