My Thoughts: Getting total no.of Checkboxes/Textboxes/Dropdowns/iframes/Links on a web page

Wednesday, May 9

Getting total no.of Checkboxes/Textboxes/Dropdowns/iframes/Links on a web page



In one of the Previous Post we had details about WebDriver findElements() method. This is very useful to find the total no.of  desired elements on a wepage .

Here are some of the examples :

Getting total no.of Links on a Webpage :
Here is the sample code to get the total no.of links on facebook registration page:
driver.get("http://facebook.com");
List  totalLinks=driver.findElements(By.tagName("a"));
System.out.println("total links "+totalLinks.size());

Getting total no.of checkboxes on a Webpage :
Here is the sample code to get the total no.of checkboxes on facebook registration page:
driver.get("http://facebook.com");
List checkboxes=driver.findElements(By.xpath("//input[@type='checkbox']"));
System.out.println("total checkboes "+checkboxes.size());



Getting total no.of dropdown menus on a Webpage :
Here is the sample code to get the total no.of dropdown menus on a facebook registration page:
driver.get("http://facebook.com");
List dropdown=driver.findElements(By.tagName("select"));
System.out.println("total dropdown lists "+dropdown.size());



Getting total no.of textboxes on a Webpage :
Here is the sample code to get the total no.of textboxes on facebook registration page:
driver.get("http://facebook.com");
List  textboxes=driver.findElements(By.xpath("//input[@type='text'[@class='inputtext']"));
System.out.println("total textboxes "+textboxes.size());

Here is the sample code to get the total no.of textboxes on hotmail registration page:
driver.get("https://signup.live.com");
List  totalTextboxes=driver.findElements(By.xpath("//input[@type='text']"));
System.out.println("total textboxes "totalTextboxes.size());

Getting total no.of iframes on a Webpage :
Here is the sample code to get the total no.of iframes :
driver.get("https://www.facebook.com/googlechrome/app_158587972131");
List  totaliFrames=driver.findElements(By.tagName("iframe"));
System.out.println("total links "+totaliFrames.size());



1 comment: