Jump to content
Sign in to follow this  

Script needs to wait for a nested iframe to be built before contnuing

Recommended Posts

I think I am very close to having my script working, but I need a little help.  I am trying to screen scrape a web-based application we use at work, and I have found that it uses nested iframes to display its information.  When viewing client's data, a new frame is created, a "Demog" frame.  If I start the script with a clients info pulled up the script works fine.  If I switch from one client to the next, everything works fine.  If I go back to the main screen (which deletes the "Demog" iframe) or start the script before the Demog iframe is created, the script will break.

I really just need this script to do nothing until it finds that particular Demog frame and then scrape the client's info and fire a function based on the acct#.

Below is the code I am using and the error I am getting with debug on.  Any and all help is appeciated.

#include <IE.au3>

$oldAcct = ""
$newAcct = ""

While 1

        $oIE = _IEAttach("**My App Name** ", "Title")
    Until $oIE <> 0

        $oFrame1 = _IEFrameGetObjByName($oIE, "frameInner")
    Until $oFrame1 <> 0

        $oFrame2 = _IEFrameGetObjByName($oFrame1, "wFrame") 
    Until $oFrame2 <> 0

        $oFrame3 = _IEFrameGetObjByName($oFrame2, "MainFrame")
    Until $oFrame3 <> 0

        $oFrame4 = _IEFrameGetObjByName($oFrame3, "Demog") 
    Until $oFrame4 <> 0

    If $oFrame4 <> 0 Then

    $oIE = 0
    $oFrame1 = 0
    $oFrame2 = 0
    $oFrame3 = 0
    $oFrame4 = 0
    Sleep(1500) ; Wait 1.5 seconds between main loops to save on CPU time


Func GetAcctInfo()
$sText = _IEBodyReadText ($oFrame4)
If $sText <> "" Then
    $Demog = StringSplit($sText,"|") ; Begin parsing data elements
    $AcctNo = StringRight ($Demog[4] , StringInStr($Demog[4], "ACCT#")-1)
    $newAcct = $AcctNo
    If $oldAcct <> $newAcct Then
        MsgBox(0,'Client Name',$Demog[1])
        MsgBox(0,'Acct #',$AcctNo)
        $oldAcct = $newAcct

Pertinent output from debugger:

0033: 0-0:  Do
0034: 0-0:      Sleep(100)
0035: 0-0:      $oFrame4 = _IEFrameGetObjByName($oFrame3, "Demog")
C:\Program Files\AutoIt3\Include\IE.au3 (800) : ==> The requested action with this object has failed.:
If $oFrame.name = $s_Name Then Return SetError($_IEStatus_Success, 0, $oTemp.frames($s_Name))
If $oFrame.name = $s_Name Then Return SetError($_IEStatus_Success, 0, $oTemp.frames($s_Name)^ ERROR
->08:18:22 AutoIT3.exe ended.rc:1

EDIT:  OK, I finally figured this out.  I updated my Autoit and IE.au3 to their latest versions and now the script works fine with no modifications.  Now I feel bad for not checking this before posting.

EDIT2:  Actually the latest code was giving me different problems, but was still erroring out around that last frame getting created/destroyed by the program  But I finally got around the issue by using a _IEFrameGetCollection loop to count the number of frames before I start looking for the correct frame.

Edited by MuffinMan

Share this post

Link to post
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
Sign in to follow this  

  • Create New...