How can I get all elements from drop down list in Selenium WebDriver?

前端 未结 11 2049
遥遥无期
遥遥无期 2020-12-11 06:10

How can I get all elements from a drop down list? I used the code below:

List elements = driver.findElements(By.id(\"s\"));
11条回答
  •  时光说笑
    2020-12-11 06:50

    This will help to list all the elements from the dropdown:

        Select dropdown = new Select(driver.findElement(By.id("id")));
    
        //Get all options
        List dd = dropdown.getOptions();
    
        //Get the length
        System.out.println(dd.size());
    
        // Loop to print one by one
        for (int j = 0; j < dd.size(); j++) {
            System.out.println(dd.get(j).getText());
    
        }
    

提交回复
热议问题