Windows Forms WebBrowser Management and Framework

I am trying to create a piece of software to more or less automate the filling out of forms on a web page, and I decided to use the WebBrowser control in System.Windows.Forms . This works fine, and I can easily manipulate the DOM through webbrowser.Document and so on. However, unfortunately, the site I'm doing automation has a file download that runs inside the iframe - and this is where I got stuck, I just can't figure out how to manage the elements inside the iframe DOM.

Ideally, what I would like to do is something like:

 HtmlElement iframe = browser.Document.GetElementById("iframe_id"); iframe.InnerDocument.GetElementById("file_upload_input").SetAttribute("value", "myfile.txt"); 

And then, of course, submit the form inside the iframe - however there is no HtmlElement attribute on the InnerDocument , as far as I can see, and not a single type that I have found so that I can distinguish the HtmlElement so that I can access the internal DOM.

How it's done?

+6
c # windows browser iframe
source share
1 answer

Try using the "frames" collection. From MSDN :

An iframe acts as a document in a document or as a floating frame. Frame collection provides access to IFrame content. Use the collection of frames to read or write elements contained in an iframe. For example, the syntax for accessing the backgroundColor style of a body object in an iframe is:

sColor = document.frames ("sFrameName") document.body.style.backgroundColor ;.

+8
source share

All Articles