Iframe access to login to page

René R

New Member
Joined
Jul 1, 2019
Messages
5
Hi All

So I have this task I have been wanting to automate for a while now..
'Login to bank, scrape the transactions, and reconcilliate to my bookings'

the login form is running through an iframe, but it doesn´t seem to be a 'normal' iframe.

below code, accesses the page, and loops through the iframes of the page, but it only returns two iframes. Not the one I´m going for.

Code also includes early binding to see if I can locate a third iframe. Not happening.

Is there anyone that can crack this.. I can´t give away login details. but if someone can input values in the highlighted 'input' fields, and hit the button.(see picture linked in the end)
I will be a very happy guy..

Code:
Option Explicit

Dim HTMLdoc As MSHTML.HTMLDocument
Dim MyBrowser As SHDocVw.InternetExplorer

Sub ConnectToNykredit()

    Dim URL As String: URL = "https://mit.nykredit.dk/erhverv/"
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim table As HTMLTable
    Dim tRow As HTMLTableRow, tCell As HTMLTableCell
    Dim iframe As HTMLIFrame
    
    Set IE = New InternetExplorer
    IE.Visible = True
    IE.navigate URL
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    Set HTMLdoc = IE.document
        
    For Each iframe In HTMLdoc.getElementsByTagName("IFRAME")
        Debug.Print iframe.ID
        Debug.Print iframe.src
    Next
    
        Set iframe = HTMLdoc.getElementsByTagName("IFRAME")(0)
        Debug.Print "0 - " & iframe.src

        Set iframe = HTMLdoc.getElementsByTagName("IFRAME")(1)
        Debug.Print "1 - " & iframe.src

        Set iframe = HTMLdoc.getElementsByTagName("IFRAME")(2)
        On Error Resume Next
        Debug.Print "2 - " & iframe.src

    IE.Quit
    Set HTMLdoc = Nothing
    Set IE = Nothing

End Sub

HTML: https://ibb.co/xKkQzrp
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
The problem is that the iframe which contains the login fields is in a different subdomain to the main page, and therefore cross-domain security prevents you accessing the HTMLDocument inside that iframe. The login iframe itself contains another iframe which is in another domain and again you can't access the HTMLDocument of this subframe. Here are the URLs:

Main page - https://mit.nykredit.dk/erhverv/
Login frame - https://netbank.nykredit.dk/signon/...d&width=500&height=450&language=da&strength=1
Login frame subframe - https://applet.danid.dk/launcher/std/1564695152228

One way around this security restriction is to navigate to the main page, then navigate to the src URL of the iframe. The code below navigates to the first two URLs, however you will see that a 'Permission denied' error occurs when it tries to access iframe.contentDocument. You might try to develop this code and navigate to this iframe's src URL (the subframe).

Code:
Public Sub IE_Test()

    Dim URL As String
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim iframe As HTMLIFrame
    
    URL = "https://mit.nykredit.dk/erhverv/"
        
    Set IE = New InternetExplorer
    IE.Visible = True
    IE.Navigate URL
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    Set HTMLdoc = IE.document
    Debug.Print IE.LocationURL

    'Get 2nd iframe element - it contains the user id and password input elements
    
    Do
        Set iframe = HTMLdoc.getElementsByTagName("IFRAME")(1)
        DoEvents
        Sleep 100
    Loop While iframe Is Nothing
    Debug.Print iframe.src
    
    'Navigate to iframe src URL - this is the Log på page
    
    IE.Navigate iframe.src
    While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
    
    '< iframe width="500" height="450" class="externalcontent" id="nemidIframe" src="https://applet.danid.dk/launcher/std/1564694577138"
    'style="background-color: transparent;" allowtransparency="true" seamless="seamless">< /iframe>
    
    Set iframe = HTMLdoc.getElementById("nemidIframe")
    Debug.Print iframe.src
    Set HTMLdoc = iframe.contentDocument            '<------ Permission denied error
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top