VBA IE Automation - Read iFrame

Our business uses a browser program for operations. I can automate the navigation solution for this site and get some data at the end.

The site itself uses the regular framework very much. However, at the very end of my process, it fills my data not in a frame, but in an iFrame. There is also very extensive javascript throughout the site, which makes things dirty.

Capturing the iFrame src URL and opening an error on the page in a new browser (that is, the error text instead of the content is displayed on the page).

My question is:

How can I extract text from iFrame via VBA?

What I've tried so far (feel free to skip):

Customize specific iFrame in specific frame and capture innerHTML

With ie.document.frames(myFrameNum).document.getElementsByTagName("iframe")(1).document.body stringResult = .innerHTML 

Configure a specific iFrame ID by ID in a specific frame and capture innerHTML

 Dim iFrm As HTMLIFrame Set iFrm = ie.document.frames(myFrameNum).document.getElementByID("iFrameID") Debug.Print iFrm.document.body.innerText 

Find any instances of iFrames and capture them (no results - maybe because iframe is embedded in the frame?)

 Dim iFrm As HTMLIFrame Dim doc As HTMLDocument For iterator = 0 To ie.document.all.Length - 1 If TypeName(ie.document.all(iterator)) = "HTMLIFrame" Then Set iFrm = ie.document.all(iterator) Set doc = iFrm.document Debug.Print & doc.body.outerHTML End If Next 
+6
source share
5 answers

I had the same problem and got the solution using the following line of script ..

IE.Document.getElementsbyTagName ("IFrame") (0). contentDocument .getElementsbyTagName ("body") (0) .innertext

+6
source

Try it...

 Dim elemCollection As IHTMLElementCollection Set elemCollection = objDoc.frames("iFrameID").document.all Debug.Print elemCollection.Item("pagemenuli-adv").innerText 
+4
source

Thanks Abkhinov .....

 IE.Document.getElementsbyTagName("iframe")(0).contentDocument.getElementsbyTagName("body")(0).innertext... 

This performed the JOB for me .....

+2
source

I ran into a similar problem, finally solved it using:

ObjIE.document.frames (0) .document.forms (0) .innerText

Note. The text I needed was present in the form that is in the iframe.

Is new to VBA, can some body explain what exactly 0 is in Frames (0) / forms (0)?

If this is something like a frame index or a frame number (by my assumption), please let me know how we can find the frame index (in any HTML)?

0
source

Try using:

 `Dim iFrm As HTMLIFrame Set iFrm = ie.document.frames(myFrameNum).document.getElementByID("iFrameID") Debug.Print iFrm.contentDocument.body.innerHTML` 
-2
source

Source: https://habr.com/ru/post/945620/


All Articles