Jump to content
Sign in to follow this  
bailey1274

Dynamically waiting for new tab to load when clicking javascript onclick event??

Recommended Posts

So my problem here is that I cannot think of any approach other than just an overkill of sleep to solve this. I have an onclick event that opens a new tab and I want to do some stuff on the new page being opened, no href or url is given. I'm using IEAttach after a sleep of 10 seconds which for the most part works but occasionally it does not because the page stays in a loading state for longer than that and since the URL is the same as the page before I have to use the 'text' option in order to successfully attach it. I can't use IELoadwait due to not having used IEAttach yet so I am not sure how to handle this. Is there any way to check the state of the browsers current page and proceed once we know the new page has actually been loaded?

Share this post


Link to post
Share on other sites

Thats where I ended up, although a new problem arose.. a NULL pointer assignment in the IEAttach Function that I cannot for the life of me figure out why is happening.

Share this post


Link to post
Share on other sites

@@ Trace(501) :            If $bIsBrowser Then
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:>Error code: 0

@@ Trace(503) :                Switch $sMode
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:>Error code: 0

@@ Trace(581) :                        If StringInStr($oWindow.document.body.innerText, $sString) > 0 Then
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:--> COM Error Encountered in Script1
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrScriptline = 581
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrNumberHex  = 00000004
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrNumber     = 4
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrWinDescr   = NULL Pointer assignment
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrDescr      = 
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrSource     = 
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrHelpFile   = 
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrHelpContext= 
2019-09-27 15:58:40 : Setup stored procedure:AA_UPDT_EXEC_LAST_ACCESS_DATE:----> $ErrLastDllErr = 0

 

It's consitently on the 15th iteration of loading the new page.. anyone have ideas on why this could be occuring??

Edited by bailey1274

Share this post


Link to post
Share on other sites

Try printing what oWindow.document.body.innertext is before checking if there is a string in it. Could it be that the string is empty on the 15 _IEAttach each time?


All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

Share this post


Link to post
Share on other sites

I ended up figuring out what it was after some trial and error. Turns out the readystate for the window was not complete. I'm guessing since the body of the document or the document itself was not available it was causing the error to occur at the Line where it checks the body for the text input criteria. I had to pull the function out locally and add a small check to make sure the $oWindow.readystate was complete before proceeding and it now works. If anyone else happens to stumble on this error then something like this should work. 

Case "html"
    While $oWindow.readystate <> 'complete' and $oWindow.readystate <> 4
        ConsoleWrite('readystate sleep')
        Sleep(2000)
    WEnd
    If StringInStr($oWindow.document.body.innerHTML, $sString) > 0 Then
        If $iInstance = $iTmp Then
            Return SetError($_IESTATUS_Success, 0, $oWindow)
        Else
            $iTmp += 1
        EndIf
    EndIf

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...