1

I am using below mentioned code in Excel VBA for IE navigation.I am facing following error while fetching data from iframe.

Error detail:

Object does not support this property or method


Option Explicit

Public Sub Cgg_Click()
    Dim Ie As New InternetExplorer
    Dim WebURL
    Dim Docx As HTMLDocument
    Dim productDesc
    Dim productTitle
    Dim price
    Dim RcdNum
    
    Ie.Visible = True
    WebURL = "https://www.google.com/maps/place/parlour+beauty+parlour+beauty/@40.7314166,-74.13182,11z/data=!4m8!1m2!2m1!1sParlour+NY!3m4!1s0x89c2599bd4c1d2e7:0x20873676f6334189!8m2!3d40.7314166!4d-73.9917443"
    Ie.Navigate2 WebURL
    
    Do Until Ie.readyState = READYSTATE_COMPLETE
        DoEvents
    Loop
    
    Application.Wait (Now + TimeValue("00:00:25"))
    
    For N = 0 To Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Length - 1
                       
        If Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Item(N).innerText = "Web results" Then
            Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Item(N).ScrollIntoView (False)
        End If
                    
    Next N
    
    Application.Wait (Now + TimeValue("00:00:25"))
         
    Set Docx = Ie.document
    
    productDesc = Docx.Window.frames("section-iframe-iframe").contentWindow.document.getElementsByClassName("trex")(0).outerHTML

End Sub

Here is the HTML:

enter image description here


Please help to resolve this error.

I want to extract "trex" ClassName HTML Contain from above url

Thanks.

2
  • Navigate directly to the src of the iframe Commented Feb 2, 2021 at 12:03
  • Please use the snippet tool via edit to insert html rather than post pictures of html. We can't copy paste from that image. See this for help or use see the formatting section of help center . Navigating using src of iframe see: stackoverflow.com/questions/44902558/… Commented Feb 2, 2021 at 12:08

1 Answer 1

2

You can change the line of extract "trex" element to one of the following, both of them can work well:

  1. Use the getElementsbyTagName method to get the Iframe first , then according to the Iframe.contentDocument property to reach the element via the class name:

    productDesc = Docx.getElementsByTagName("iframe")(0).contentDocument.getElementsByClassName("trex")(0).outerHTML
    
  2. Use querySelector method to get the Iframe through class, then use the same as the above to reach the element:

    productDesc = Docx.querySelector(".section-iframe-iframe").contentDocument.getElementsByClassName("trex")(0).outerHTML
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.