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

后端 未结 11 850
闹比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:52

    To get all the dropdown values you can use List.
    
    List lstDropDownValues = new List();
    int iValuescount = driver.FindElement(By.Xpath("\html\....\select\option"))
    
    for(int ivalue = 1;ivalue<=iValuescount;ivalue++)
     {
      string strValue = driver.FindElement(By.Xpath("\html\....\select\option["+ ivalue +"]"));
      lstDropDownValues.Add(strValue); 
     }
    

提交回复
热议问题