htmlElement helpl

gkiril

Newcomer
Joined
Feb 15, 2004
Messages
21
Hello,

I'm hoping someone can help. I have an html document with three frames, topFrame, middleFrame, and bottomFrame. I have the document loading in a webBrowser control in VB .net 2005. I have a button on my form and when the button is clicked, I want to add text to a text box in the bottom frame. All documentation on MSDN and what I have found online shows that the following simple code should work, but I get an error message when the button is clicked. Please help if you can. Here is the code I am trying to execute:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim hElement As HtmlElement = WebBrowser1.Document.GetElementById("parent.bottomFrame.document.getElementById('text')")

hElement.SetAttribute("value", "test")

End Sub



The error (NullReferenceException was Unhandled) that is displayed has to do with the .SetAttribute line. Thanks in advance. -gk
 
Yeah, the problem is the frame(s). I discovered this bit of code:

Dim variable As HtmlDocument
Dim variable2 as HtmlElement
variable = WebBrowser1.Document.Window.Frames(2).Document
variable2 = variable.GetElementById("element")

variable2.setAttribute("value", "test text")

This works with .invokeMember also...

So, this answers the question that I originally had and hopefully will pave the way for my using .invokeScript now that I know that I have to identify the frame where these actions are taking place.

If someone can provide some insight on how to obtain the highlighted text in an HTML page hosted in a WebBrowser control and add that text to a text box on the form (preferably without using javascript, but any solution will do), I would be grateful.

Thanks for looking.

-gk
 
Getting highlighted text in a WebBrowser control has also been solved. Please consider this thread closed.

-gk
 
Back
Top