How to get all options in a drop-down list by Selenium WebDriver using C#?

后端 未结 11 890
闹比i
闹比i 2020-12-30 02:30

I\'m new to both C# and Selenium WebDriver.

I know how to select/click on an option in a drop-down list, but I\'ve a problem before that. Since the drop-down list i

11条回答
  •  被撕碎了的回忆
    2020-12-30 02:50

    Here is code in Java to get all options in dropdown list.

    WebElement sel = myD.findElement(By.name("dropdown_name"));
    List lists = sel.findElements(By.tagName("option"));
        for(WebElement element: lists)  
        {
            String var2 = tdElement.getText();
            System.out.println(var2);
        }
    

    Hope it may helpful to someone.

提交回复
热议问题