How to find no. Of elements starts with land in selenium drop-down and count them

Select se= new select(locator of drop-down);
List<webelemts> list= se.getoptions();

For(int l: list){}

Not sure as I want to select all countries starts ends with land and count the no. Of them and print.


You can simply create a int counter and initial value will be set to 0.

also using the below for each loop, you can iterate all the options and using .getText() method, you can use .startsWith or .endsWith like below.

int counter = 0;
Select se = new Select(driver.findElement(By.xpath("select web element xpath here")));
List<WebElement> list = se.getOptions();
for (WebElement ele : list) {
    if(ele.getText().startsWith("land") || ele.getText().endsWith("land")) {

and then finally print the counter,