How to count the number of drop down values present in a dropdown list using selenium webdriver

package selenium_examples;


import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class spicejet {

public static void main(String[] args) {


WebDriver driver = new FirefoxDriver();
driver.get("http://newtours.demoaut.com");
driver.findElement(By.name("userName")).sendKeys("mercury");
driver.findElement(By.name("password")).sendKeys("mercury");
driver.findElement(By.name("login")).click();
driver.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS);

WebElement we = driver.findElement(By.name("fromPort"));

java.util.List options =  we.findElements(By.tagName("option"));

System.out.println("Dropdown values count = " + options.size());

driver.close();


}
}

Output :-

Dropdown values count = 10

selenium webdriver scripts

Above script logins into Mercury tours website and gets count of number of drop down values present in "Departing From" dropdown list.






No comments:

Related Posts Plugin for WordPress, Blogger...