尝试使用Selenium WebElement从下拉列表中检索数组或列表中的值

尝试使用Selenium WebElement从下拉列表中检索数组或列表中的值,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我试图将下拉元素中的所有值放入数组或列表中。您能告诉我是否有提供的功能或方法吗?Select.getOptions出现在我的脑海中 有关更多信息,请阅读。如果您对上述代码感到满意,请选择上箭头。此答案非常有用 import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement

我试图将下拉元素中的所有值放入数组或列表中。您能告诉我是否有提供的功能或方法吗?

Select.getOptions出现在我的脑海中


有关更多信息,请阅读。

如果您对上述代码感到满意,请选择上箭头。此答案非常有用
    import java.util.List;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class Example {
    public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.Example.com/");
    //List the Values
    List<WebElement> options = driver.findElements(By.xpath("//*[@id='m']//option"));
    //Count the Values
    System.out.println(options.size());

    for(int i=0;i<options.size();i++){
    //Print the text
    System.out.println(options.get(i).getText());

    String optionName = options.get(i).getText();
    //If u want to select the perticular Value
    if(optionName.equals("xxxxx")){

    options.get(i).click();

    }
    }
    }
    }