DotNetBrowser DOM API allows working with HTML SELECT and OPTION elements. To work with SELECT element, the DOMSelectElementclass is used. Let's see how to access SELECT element on the web page that contains the following HTML code:


<select id='select-tag'>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>


To access SELECT element use the following DotNetBrowser API:


DOMDocument document = browser.GetDocument();
DOMSelectElement select = (DOMSelectElement) document.GetElementById("select-tag");


Now, using the select instance you can get information about its options, programmatically select the specified option. To work with OPTION element, the DOMOptionElement class is used. For example:


List<DOMOptionElement> options = selectElement.Options;
DOMOptionElement option = options[index];
option.Selected = true;


The complete sample you can find by the following link:


Note: The onchange event is not fired when the dropdown selection is changed programmatically.
You need to fire the onchange event manually after changing the dropdown selection.

The sample code below demonstrates how to select the option by its value and fire the onchange event:

string expectedValue = "Opel";

List<DOMOptionElement> options = selectElement.Options;
foreach (DOMOptionElement option in options)
{
    string value = option.InnerText;
    if (expectedValue.Equals(value))
    {
        option.Selected = true;
        var myEvent = e.Browser.CreateEvent("change");
        selectElement.DispatchEvent(myEvent);
    }
}