简体   繁体   中英

Using .Net Web Control - How to Set a Value in a TextBox *INSIDE* of an IFRAME

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

Access to frames is complicated by the fact that the managed HTML DOM implements a security measure known as cross-frame scripting security. If a document contains a FRAMESET with two or more FRAMEs in different domains, these FRAMEs cannot interact with one another. In other words, a FRAME that displays content from your Web site cannot access information in a FRAME that hosts a third-party site such as http://www.adatum.com/ . This security is implemented at the level of the HtmlWindow class. You can obtain general information about a FRAME hosting another Web site, such as its URL, but you will be unable to access its Document or change the size or location of its hosting FRAME or IFRAME.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM