I’m trying to use a .Net WebBrowser control to log into a website and aggregate some data for me. I’m also using a reference to MSHTML (but I don’t care if your solution does or doesn’t).
When I visit a ‘normal’ website – I create an mshtml.HTMLDocument from the webBrowser’s .documment. Then I create a mshtml.FormElement and a mshtml.HTMLInputElement using the name of the textbox I want.
Then, I can set the value of the textBox.
It looks something like this:
Dim myDoc1 As mshtml.HTMLIFrame = DirectCast(Me.WebBrowser.Document.DomDocument, mshtml.HTMLDocument) Dim myForm As mshtml.HTMLFormElement = DirectCast(myDoc1.forms.item(0), mshtml.HTMLFormElement) Dim myUserBox As mshtml.HTMLInputElement = DirectCast(myForm.item('user'), mshtml.HTMLFormElement) myUserBox.value = UserName
My problem is that on some websites the textbox I need to manipulate is contained inside of an IFRAME. An example would be https://servicing.capitalone.com/c1/login.aspx
If my program surfs to that site – it can’t find a textbox for the Username – because there isn’t one. There is only an IFRAME tag that has a URL of ‘https://login.capitalone.com/loginweb/login/login.do‘
If I surf directly to the login.do page – the website redirects me to an error page.
How can I enter data into the UserName textbox in that IFRAME?
Because the child iframe you are trying to access is coming from a different domain than the parent page, you won’t be able to access the form elements of the iframe due to cross-frame scripting security. See: Accessing Frames in the Managed HTML Document Object Model