Back To Normal

Subscribe To Our E-Mail Newsletter

Thursday, July 26, 2012

Types of locaters in Selenium Webdriver


Couch ModePrint It

Types :  
  • Finding element by id
  • Finding elemeny by name 
  • Finding element by link.
  • Finding element by Xpath.
  • Finding element by CSS
  • Findidng element by DOM
  • Finding child eleme
Finding element by id :

 
For Example : driver.findElement(By.id(userid));

 
Finding elemeny by name :

 
driver.findElement(By.name("logon"));

 
Finding element by link:

 
driver.findElement(By.linkText("rank list"));

 
driver.findElement(By.partialLinkText("rank"));

 
Finding element by Xpath:

 
-- To find xpath user can use fire bug.

 
//table/tr[2]/td/input

 
//input[@id='item_quantity']

 
(//table[@name='cart']//input)[2]

 
//input[contains(@class,'required')]

 
//input[contains(@class,'required') and type='text']

 
some more options..

 
// xpath iposition

 
//Xpath relative

 
Finding element by CSS

 
driver.findElements(By.css("input[class~='required']"));
driver.findElements(By.class("required"));

 
Finding elements by DOM

 
document.forms[0].elements[0]

 
document.forms['loginOut'].elements['username']

 

Click Here For Smileys :D
:D
:)
:[
;)
:D
:O
(6)
(A)
:'(
:|
:o)
8)
(K)
(M)

No comments:

560 Free Online Courses

Top 200 universities launched 500 free online courses.  Please find the list here .