WebBrowser control HTMLDocument automate selecting option drop-down

Posted by CWinKY on Stack Overflow See other posts from Stack Overflow or by CWinKY
Published on 2010-02-28T15:40:15Z Indexed on 2010/05/06 19:08 UTC
Read the original article Hit count: 935

Filed under:
|
|
|
|

I'm trying to automate in a WinForm using a WebBrowser control to navigate and pull report info from a website. You can enter values in textboxes and invoke the click events for buttons and links, but I have not figured out how select a option drop-down .... in a automated way. Anybody recommend how to select a item from a drop-down, given this html example:

<SELECT id="term_id" size="1" name="p_term_in"><option value="">Select Another Term<option value="201050">Summer 2010<option value="201010">Spring 2010<option value="200980">Fall 2009</SELECT>

For others that can learn from entering values to textboxes and invoking click events here's how you do it:

webBrowser1.Document.GetElementById("<HTML ELEMENT NAME>").SetAttribute("value", "THE NAME");

Invoke button or hyperlink click:

webBrowser1.Document.GetElementById("<BUTTON>").InvokeMember("click");

So I've solved entering values and invoking click, but I have not solved selecting a drop-down value.

© Stack Overflow or respective owner

Related posts about c#

Related posts about webbrowser