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"); ListtotalLinks=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"); Listcheckboxes=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"); Listdropdown=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"); Listtextboxes=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"); ListtotalTextboxes=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"); ListtotaliFrames=driver.findElements(By.tagName("iframe")); System.out.println("total links "+totaliFrames.size());
great work... thanks a lot
ReplyDelete