Select each option in a drop down using Selenium WebDriver C#

后端 未结 5 1794
深忆病人
深忆病人 2021-02-19 00:06

I\'m not able to select options in a drop down list. I think I need to have .Select or SelectElement, but there is no such option.

Sample code:

5条回答
  •  有刺的猬
    2021-02-19 00:40

    Use the below simple sample code:

    String Input="Value to Select"; 
    String xPathVal="@["id=Samplexpath"]"; 
    IWebElement TargetElement = driver.FindElement(By.XPath(xPathVal)); 
    SelectElement dropdown = new SelectElement(TargetElement); 
    dropdown.SelectByText(Input.Trim());
    

提交回复
热议问题