Posted By: otech | Jun 21st, 2006 @ 3:28 AM
page 1 of 1
Comments: 1 | Views: 4493
otech
otech
digital voice recording systems
Guys, I have looked everywhere but cannot find the way to read / set a value in an input field using the Browser control in VB.Net 2005.

In VS 2003 (.Net 1.1) the axWebBrowser Control would allow:

field value = Browser.Document.GetElementsByName("element_name").value()

or

Browser.Document.GetElementsByName("element_name").value() = "new value"

These functions no longer appear to work, and I have been searching around for hours and hours trying to find the new method for this simple operation.

Please, anyone who knows, lend me a hand and I will be forever grateful!!

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
The WebBrowser control does not directly expose the entire DOM interface, but you can still accomplish what you want.

It seems it would be better if you give your input element an "id" attribute and use GetElementById to find it.

Perhaps the easiest way is to use the interfaces presented by the WebBrowser control:

Dim value As String = Browser.Document.GetElementById("element_id").GetAttribute("value")
Browser.Document.GetElementById("element_id").SetAttribute("value", "new value")

You can also access the unmanaged DOM interface, which thanks to late binding in VB is quite easy:

Dim value As String = Browser.Document.GetElementById("element_id").DomElement.value
Browser.Document.GetElementById("element_id").DomElement.value = "new_value"

If you want to keep using GetElementsByName (for instance if you don't have control over the HTML you're accessing) you'll have to switch to the unmanaged DOM interface at the document level:

Dim value As String = Browser.Document.DomDocument.getElementsByName("element_name")(0).value
Browser.Document.DomDocument.getElementsByName("element_name")(0).value = "new value"
page 1 of 1
Comments: 1 | Views: 4493
Microsoft Communities