Using Selenium (C#) how do I select an item from a drop-down list



  • I'm using the Selenium IDE to record my initial tests and then export them to c# and then use the webdriver. Some things that I do from the IDE don't export.

    I am trying to select a State from a drop-down text list. I don't have much background in HTML and am kind of new to C# also (I've programmed for a couple semesters in Java so far, c# for about a month.) How would I go about selecting a specific state from the dropdown list?



  • I'm assuming you're using Firefox? Right-click the drop-down list and select "Inspect Element". Get the tag from the information (everything in green following the pound sign). Then add this to your code where you need to select the element

    new SelectElement(driver.FindElement(By.Id("{put your tag information here}"))).SelectByText("{State here}");
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2