Jump to content

How to manage several frames separately?


evg64
 Share

Recommended Posts

I have an opened Internet Explorer Window, which contains 2 frames. How can I manage these frames separately? For example, how can I get HTML of each frame?

The following code doesn`t help:

$obj = _IEAttach ("Window title")

$string=_IEBodyReadHTML($obj)

Link to comment
Share on other sites

I have an opened Internet Explorer Window, which contains 2 frames. How can I manage these frames separately? For example, how can I get HTML of each frame?

The following code doesn`t help:

$obj = _IEAttach ("Window title")

$string=_IEBodyReadHTML($obj)

Get the object reference for the frames:

$oIE = _IEAttach ("Window title")
$colFrames = _IEFrameGetCollection($oIE)
$iFrameCnt = @extended
ConsoleWrite("There are " $iFrameCnt " frames." & @LF)
$i = 0
For $oFrame In $colFrames
    ConsoleWrite("Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)
    $i += 1
Next

You can get a single reference to a frame by name, or by 0-based index number. Look at _IEFramGetCollection() and _IEFrameGetObjByName in the help file and play with the examples there.

:D

Edit: Tweaked to put increment for $i in place.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Get the object reference for the frames:

$oIE = _IEAttach ("Window title")
$colFrames = _IEFrameGetCollection($oIE)
$iFrameCnt = @extended
ConsoleWrite("There are " $iFrameCnt " frames." & @LF)
$i = 0
For $oFrame In $colFrames
    ConsoleWrite("Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)
Next

You can get a single reference to a frame by name, or by 0-based index number. Look at _IEFramGetCollection() and _IEFrameGetObjByName in the help file and play with the examples there.

:D

I cant understand the problem, but the following loop doesnt work correctly:

For $oFrame In $colFrames

ConsoleWrite("Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

Next

The page where I tested the script contains 2 frames and program showed that but then it doesnt show HTML-code of the frames.

P.S. I changed the loop in this way:

For $oFrame In $colFrames

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

Next

msgbox(0,0,$i)

It was shown that $i=0.

Edited by evg64
Link to comment
Share on other sites

I cant understand the problem, but the following loop doesnt work correctly:

For $oFrame In $colFrames

ConsoleWrite("Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

Next

The page where I tested the script contains 2 frames and program showed that but then it doesnt show HTML-code of the frames.

P.S. I changed the loop in this way:

For $oFrame In $colFrames

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

Next

msgbox(0,0,$i)

It was shown that $i=0.

Doh! :D

Forgot to increment $i. Just add this to the loop:

$i += 1

Aside from that, it should have worked, unless the frames are not at the top of the DOM. Are they inside another frame, or an iFrame, or what? You might want to hunt down DebugBar for IE and see what the path to those frames looks like.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I did as u said:

For $oFrame In $colFrames

$i += 1

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

Next

but it still doesnt work(( Where can I download debugger? I tried to find it myself but I couldnt.

You asked me about frames. The page contains 2 frames and something else (I dont know exactly what it is). HTML of the last unknown part describes these 2 frames: their ID and names.

Link to comment
Share on other sites

I did as u said:

For $oFrame In $colFrames

$i += 1

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

Next

but it still doesnt work(( Where can I download debugger? I tried to find it myself but I couldnt.

You asked me about frames. The page contains 2 frames and something else (I dont know exactly what it is). HTML of the last unknown part describes these 2 frames: their ID and names.

You want that increment to come after the MsgBox(), because the frames are numbered from 0.

Find any post by DaleHohm. He has a link to DebugBar in his sig, or just Google it. It is an addon to IE that will display path of DOM objects to an object in a web page.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You want that increment to come after the MsgBox(), because the frames are numbered from 0.

I changed the code:

For $oFrame In $colFrames

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

$i += 1

Next

msgbox(0,0,$i)

When the loop finishes, $i=0. I guess the problem is that the loop doesnt "work".

P.S. I downloaded debugger, it showed that main document contains 3 frames. The second one contains some frames - one of these last frames is exactly I need to refer to! =)

Link to comment
Share on other sites

I changed the code:

For $oFrame In $colFrames

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

$i += 1

Next

msgbox(0,0,$i)

When the loop finishes, $i=0. I guess the problem is that the loop doesnt "work".

P.S. I downloaded debugger, it showed that main document contains 3 frames. The second one contains some frames - one of these last frames is exactly I need to refer to! =)

You forgot this part:
$iFrameCnt = @extended
ConsoleWrite("There are " $iFrameCnt " frames." & @LF)

If the frame count in the collection is 0, there is nothing to loop on. That is exactly what you expect if the frames are contained inside another object, like an iframe. Look in the help file at the example under _IEIsFrameSet().

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You forgot this part:

$iFrameCnt = @extended
ConsoleWrite("There are " $iFrameCnt " frames." & @LF)

If the frame count in the collection is 0, there is nothing to loop on. That is exactly what you expect if the frames are contained inside another object, like an iframe. Look in the help file at the example under _IEIsFrameSet().

:D

The whole my program looks so:

#include <IE.au3>

$oIE = _IEAttach ("Wizards World")

$colFrames = _IEFrameGetCollection($oIE)

$iFrameCnt = @extended

msgbox(0,0,"There are "& $iFrameCnt& " frames." & @LF)

msgbox(0,0,_IEIsFrameSet($colFrames))

$i = 0

For $oFrame In $colFrames

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

$i += 1

Next

msgbox(0,0,$i)

Results (messages in msgbox):

1) There are 2 frames.

2) 1

3) 0

So how to get html of a frame?

Link to comment
Share on other sites

The whole my program looks so:

#include <IE.au3>

$oIE = _IEAttach ("Wizards World")

$colFrames = _IEFrameGetCollection($oIE)

$iFrameCnt = @extended

msgbox(0,0,"There are "& $iFrameCnt& " frames." & @LF)

msgbox(0,0,_IEIsFrameSet($colFrames))

$i = 0

For $oFrame In $colFrames

msgbox(0,0,"Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)

$i += 1

Next

msgbox(0,0,$i)

Results (messages in msgbox):

1) There are 2 frames.

2) 1

3) 0

So how to get html of a frame?

Hmm... evidently a FrameSet is not a collection object as returned by _IEFramGetCollection(). That was news to me.

Using indexes works:

#include <IE.au3>

$oIE = _IE_Example("FrameSet")
$colFrames = _IEFrameGetCollection($oIE)
$iFrameCnt = @extended
MsgBox(0, 0, "There are " & $iFrameCnt & " frames." & @LF)
MsgBox(0, 0, "_IEIsFrameSet() = " & _IEIsFrameSet($colFrames))

; This method failed...
; $i = 0
; For $oFrame In $colFrames
;   MsgBox(0, 0, "Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)
;   $i += 1
; Next

; This works
For $i = 0 To $iFrameCnt - 1
    $oFrame = _IEFrameGetCollection($oIE, $i)
    MsgBox(0, 0, "Frame " & $i & ":" & _IEBodyReadHTML($oFrame) & @LF)
Next
MsgBox(0, 0, $i)

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...