3

I am working on an automation which opens an intranet site in Internet explorer, inputs data and submit the information.

However the site is using multiple 'iframes' and 'frames' i.e. Under top level 'iframe', there will be another 'iframe' and inside that there will be another 'frame' which has the buttons and text boxes.

Top level iframe
  --control 1
  --control 2
  ....
  Second iframe
    ....
    Third iframe
    --control 1
    --control 2

I was able to access controls under the top level 'iframe', however my code is not identifying second 'iframes' onward and its elements.

How can I accomplish that?

Below is my code (frmMain is the top level iframe, modelframe1 and modalframe2 are the second and third ones)

Set doc = ie.Document

Set iframeDoc = doc.frames("frmMain").Document

Set objCollection = iframeDoc.getElementsByTagName("input")
objCount = 0
While objCount < objCollection.Length
    Debug.Print objCollection(objCount).Name
    If objCollection(objCount).Type = "submit" And objCollection(objCount).Name = "abc_name" Then 
        Set objElement = objCollection(objCount)
        objElement.Click
    End If
    objCount = objCount + 1
Wend 
Joseph K
  • 31
  • 2
  • Do you need to interact with all frames? i.e. input data into each? – QHarr Aug 26 '20 at 15:46
  • Yeah at least to 3 levels – Joseph K Aug 26 '20 at 16:02
  • Can you share the relevant html? If they are all nested iframes, do they all have an src attribute that has a full url? – QHarr Aug 26 '20 at 17:47
  • This is the image https://ibb.co/VWjN7hd, i can't share full code as it is confidential. This page has nested frames, inside each frame there is another HTML page with iframe, please see the highlighted ones – Joseph K Aug 26 '20 at 18:17
  • 2
    If you can access the src at top level then you can .navigate to it and when that document has loaded repeat for the next src and so on. Otherwise you need to descend the nested documents via contentdocument of each iframe node. Examples are many on SO for vba + iframe e.g. https://stackoverflow.com/questions/44902558/accessing-object-in-iframe-using-vba/44952913 – QHarr Aug 26 '20 at 18:20
  • 1
    If you hit permission errors check if due to same origin policy. If that is the case, you will need to try automating FF or Chrome with Selenium basic and using SwitchToFrame – QHarr Aug 26 '20 at 18:26

0 Answers0