Back To Normal

Subscribe To Our E-Mail Newsletter

Friday, July 27, 2012

Find child elements : Selenium Web driver


When same object is getting duplicated for N number of parent, then user can refer parent and child relationship to identify the object in browser.

WebElement bodyElement = driver.findElement(By.id("body"));
WebElement bodyElement1 = bodyElement.findElement(By.id("body"));
System.out.println(bodyElement1.findElement(By.id("TotalScore")).getText());

User want to read all child elements of div(parent) container by using following methods.

WebElement bodyElement = driver.findElement(By.id("body"));  
List divElements = bodyElement.findElements(By.className("div"));
for(WebElement childDiv : divElements){
 List fieldSetEle = childDiv.findElements(By.tagName("fieldset"));
 System.out.println(childDiv.getTagName()+":"+fieldSetEle.size());
    }  
Read More


Thursday, July 26, 2012

Types of locaters in Selenium Webdriver

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']

 
Read More


560 Free Online Courses

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