Pick value in dropdown combo on WebBrowser page

B

BobRoyAce

I have a WebBrowser on a form and I am automating some data entry on
pages displayed therein. I know how to select/click on a radio button
or checkbox. I know how to set the value of a text box. But, how do I
programmatically set the value picked in a drop down? I tried the
following:

Dim oHtmlElement As HtmlElement
oHtmlElement = WebBrowser1.Document.GetElementById("cboGroups")
oHtmlElement.InnerText = "Group 1"

but that doesn't work, even though "Group 1" is one of the options in
the dropdown.
 
A

angelo.ferretti

I have a WebBrowser on a form and I am automating some data entry on
pages displayed therein. I know how to select/click on a radio button
or checkbox. I know how to set the value of a text box. But, how do I
programmatically set the value picked in a drop down? I tried the
following:

  Dim oHtmlElement As HtmlElement
  oHtmlElement = WebBrowser1.Document.GetElementById("cboGroups")
  oHtmlElement.InnerText = "Group 1"

but that doesn't work, even though "Group 1" is one of the options in
the dropdown.

try with this (sorry only in C#, you have to translate it):

HtmlElement el = webBrowser1.Document.All["cboGroups"];
el.Children.SetAttribute("selected", "x");

where i is the index of the item you want to select

Angelo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top