guys! I have to set some fields values automatically through code in my win forms application, which contains a web browser. The only thing not working is setting value in multiselect. I can click buttons through code, set textbox fields and etc, but the multiselect list do not work (can't set value properly). First of all, this is the HTML code in the page for this element:
<select size="10" name="someName" multiple="multiple" onchange="javascript:setTimeout('someFunc')" id="elementId" showconfirmedonly="true" showextraitems="true">
<option selected="selected" value="1">First opt</option>
<option value="2">Second opt</option>
<option value="3">Third opt</option>
<...other options...>
</select>
I try to deselect all the elements first this way:
webBrowser.Document.GetElementById(elementId).InnerHtml =
webBrowser.Document.GetElementById(elementId).InnerHtml.Replace(
"<option selected=\"selected\"", "<option");
and then I try to select (only one) the desired element(value) this way:
webBrowser.Document.GetElementById(elementIWantToSelectId).Focus();
element.SetAttribute("selected", "selected");
webBrowser.Document.GetElementById(elementIWantToSelectId).InvokeMember("onchange");
First i must deselect the selected options, and select my desired single option. If I try only to change the html with the Replace method , it doesn't work, neither with only setting selected attribute. The other fields in the page change when any value changes (when onchange func is called - I must invoke it when setting value anywhere) and that's why I have to invoke 'onchange' function. When the code executes, all the options disappear and the multiselect box is empty, which I find really strange. Any suggestions how to solve my problem would be appreciated.