I am working on a simple application that automatically browses in a page that contains two dropdown menus and a button. The page looks like this:
——DropDown1——-
——DropDown2——-
——-Button———
Now, the problem is, the contents of DropDown2 is dynamically generated by the selection of Dropdown1.
I wrote code like this in c#:
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement elem = webBrowser1.Document.GetElementById("DropDown1");
elem.SetAttribute("selectedIndex", "1");
elem.RaiseEvent("onChange");
HtmlElement elem = webBrowser1.Document.GetElementById("DropDown2");
elem.SetAttribute("selectedIndex", "5");
elem.RaiseEvent("onChange");
}
After raising the onChange event, the browser loads the new values but I can’t get and set the DropDown2 value because the document still thinks DropDown2s values are empty.
How can I get and set the new values that are generated in DropDown2?
i have found the solution by invoking “__doPostBack” script after raising onChange event. when i invove the doPostBack, the document reloads and so i can retrieve the new values. heres the code: