gkiril Posted February 21, 2008 Posted February 21, 2008 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 Quote
Administrators PlausiblyDamp Posted February 21, 2008 Administrators Posted February 21, 2008 It looks as though the GetElementById call isn't finding the element and therefore returning Nothing - are you sure the element does exist? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
gkiril Posted February 21, 2008 Author Posted February 21, 2008 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 Quote
gkiril Posted February 28, 2008 Author Posted February 28, 2008 Getting highlighted text in a WebBrowser control has also been solved. Please consider this thread closed. -gk Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.