10101
10101

Reputation: 2402

Access fields inside iframe

For some reason I am not able to access elements inside iframe.

I have tried:

ie.Document.getElementById("sisaltosivu").contentDocument.getElementById("uusihaku")(0).Click

Here is my code:

Sub ChechAutomate()

    Dim ie As New InternetExplorer, url As String, ws As Worksheet

    Set ws = ThisWorkbook.Sheets("Other Data")

    url = "https://www.asiakastieto.fi/data/atdb"

    With ie
        .Visible = True
        .Navigate2 url

        While .Busy Or .ReadyState < 4: DoEvents: Wend

        With .Document

        If .querySelectorAll("#btnb").Length > 0 Then

        Else

            .querySelector("[name=user1]").Value = "x"
            .querySelector("[name=user2]").Value = "x"
            .querySelector("[name=passwd]").Value = "x"
            .querySelector("[class=btnb]").Click

            Application.Wait (Now + TimeValue("00:00:01"))

            ie.Navigate2 "https://www.asiakastieto.fi/sopimusasiakas/kotimaa?lang=FI"

            Application.Wait (Now + TimeValue("00:00:01"))
             ie.Document.getElementById("sisaltosivu").contentDocument.getElementById("uusihaku")(0).Click

        End If

        End With

    End With

End Sub

enter image description here

Upvotes: 0

Views: 55

Answers (1)

QHarr
QHarr

Reputation: 84465

You are no longer outside the iframe when you navigate to the src of the iframe. This line:

ie.Navigate2 "https://www.asiakastieto.fi/sopimusasiakas/kotimaa?lang=FI"

should mean you are now in the document referenced within the iframe and should access direct with:

.document.getElementById("uusihaku")(0).Click

Upvotes: 1

Related Questions