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:
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<webelement> checkboxes=driver.findElements(By.xpath("//input[@type='checkbox']"));
System.out.println("total checkboes "+checkboxes.size());
</webelement>
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<webelement> dropdown=driver.findElements(By.tagName("select"));
System.out.println("total dropdown lists "+dropdown.size());
</webelement>
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 <webelement> textboxes=driver.findElements(By.xpath("//input[@type='text'[@class='inputtext']"));
System.out.println("total textboxes "+textboxes.size());
</webelement>
Here is the sample code to get the total no.of textboxes on hotmail registration page:
driver.get("https://signup.live.com");
List <webelement> totalTextboxes=driver.findElements(By.xpath("//input[@type='text']"));
System.out.println("total textboxes "totalTextboxes.size());
</webelement>
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 <webelement> totaliFrames=driver.findElements(By.tagName("iframe"));
System.out.println("total links "+totaliFrames.size());
</webelement>
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:
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<webelement> checkboxes=driver.findElements(By.xpath("//input[@type='checkbox']"));
System.out.println("total checkboes "+checkboxes.size());
</webelement>
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<webelement> dropdown=driver.findElements(By.tagName("select"));
System.out.println("total dropdown lists "+dropdown.size());
</webelement>
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 <webelement> textboxes=driver.findElements(By.xpath("//input[@type='text'[@class='inputtext']"));
System.out.println("total textboxes "+textboxes.size());
</webelement>
Here is the sample code to get the total no.of textboxes on hotmail registration page:
driver.get("https://signup.live.com");
List <webelement> totalTextboxes=driver.findElements(By.xpath("//input[@type='text']"));
System.out.println("total textboxes "totalTextboxes.size());
</webelement>
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 <webelement> totaliFrames=driver.findElements(By.tagName("iframe"));
System.out.println("total links "+totaliFrames.size());
</webelement>