Jump to content

how to wait until a new web page opened by javascript is ready?


Go to solution Solved by water,

Recommended Posts

Hello
I'm trying to automate an web application that is build with frames and a lot of javascipt,
the first page is a login page with 2 input box (username and password) and a login button
no problems to automate input of credentials and click button  on this page

#include <ie.au3>
$oIE = _IECreate ("https://mypage:7493/idem/suite/login.do")

$oFrame = _IEFrameGetCollection($oIE, 0) ; first frame (frame 0)

$oForm = _IEFormGetObjByName ($oFrame, "basicLogonForm"); this form is inside the frame

$oQuery1 = _IEFormElementGetObjByName ($oForm, "username") ; first field inside the form
$oQuery2 = _IEFormElementGetObjByName ($oForm, "userpassword") ; second field inside the form

$uname="MyUsername"
$pwd="MyPassword"

_IEFormElementSetValue ($oQuery1,$uname) ; input username
_IEFormElementSetValue ($oQuery2,$pwd) ; input password

$oButton=_IEGetObjById($oFrame,"button") ; reference to button

_IEAction ($oButton, "click") ; click on button

_IELoadWait($oIE) ; <=== here, the script goes on without waiting
                  ; and following statements give error

; Sleep ( 10000 ) ; if I force waiting, the script give no error
                  ; because the new page has time to load itself

Local $oFrame = _IEFrameGetObjByName($oIE, "main-frame") ; new frame in the new page

$oForm = _IEFormGetObjByName ($oFrame, "SimpleSearchfrm"); new form in new page

$oQuery1 = _IEFormElementGetObjByName ($oForm, "simplesearchquery")

_IEFormElementSetValue ($oQuery1,"nametosearch")

.... etc ....

but after clicking the button, the second page that is displayed, is loaded by some javascript function (i guess something like top.location.replace("login.do")
the problem (in line 30) is that i am not able to wait till the new page is loaded,  and so the script goes on while the new page is not ready, causing errors.
i tryed to use the  _IELoadWait($oIE) function but with no success, maybe it is not the right function in this context.

I would need some suggestions

thank you

Edited by Pincopanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Did you read the remarks in the help file for _IELoadWait?

"... prevent _IELoadWait from guaranteeing that a page is fully loaded ... use Sleep command, examining browser status bar text and other methods ..."

Another method would be to wait until a specific object exists.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You will need to do your own check to see when the page is done loading.  For example, if the issue is "simplesearchquery" doesn't exist yet, write a loop that checks for its existence every 200ms.  "simplesearchquery" is of course just an example, and you will need to find out exactly what you are waiting for the javascript to create.  Javascript/ajax will commonly run asynchronously, so there is no way for the browser to know when it is finished and report it to you.

EDIT: ninja'd by water :P

Edited by danwilli
Link to comment
Share on other sites

just faster fingers ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Use _IEGetObjById in a loop while @error = 7

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

... I can not find the solution
I try in this way to wait until an object exists in the browser

Do
Local $oFrame = _IEFrameGetObjByName($oIE, "main-frame")
ConsoleWrite("error: " & @error & @CRLF)
Until @error

but I get this error

C:Program Files (x86)AutoIt3Includeie.au3 (813) : ==> 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
->11:42:06 AutoIT3.exe ended.rc:1
>Exit code: 1    Time: 3.011

and the script exits

any help is welcome

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

To prevent your script from crashing call _IEErrorHandlerRegister (with the default or a custom error handler).

Or run your script with Beta version 3.3.9.x of AutoIt.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

.. still NOT out of troubles ..

I modified my script like this:

_IEErrorHandlerRegister ()

Do
    Sleep(500)
    Local $oFrame = _IEFrameGetObjByName($oIE, "main-frame")
    
;  Until not @error ; DO NOT WORK
;  Until  $oFrame <> 0   ; DO NOT WORK

  Until ???until_WHAT???

but I do not know how to exit from the Do / Until loop
which condition do I have to check in the Until ?????
what is the condition that tells me that the object has been created?

Until not @error do not works
Until $oFrame <> 0 do not works

:unsure:  please, any help is welcome .... Thank You

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Solution

Try "Until IsObj($oFrame)" because _IEFrameGetObjByName returns an object.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks water

Until IsObj($oFrame) it worked

but I was not right in my previous post;

Until $oFrame <> 0 also works,

I was confused by successive errors that came from other objects that still was not build. ( forms, and FormElements) that I referenced too early.

so I realized that I have to use Do / Until loops for any alement of the web page, or, much better,  at least for the last one element of the web page that will be build.

..... now i feel better .....

Thanks again water for your support.
Bye

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

so I realized that I have to use Do / Until loops for any alement of the web page, or, much better,  at least for the last one element of the web page that will be build.

That's what I would do too. Wait until the last element on the page exists.

Or check the status line. Maybe a "Ready" or something appears or a "Loading" vanishes when the page has finished loading.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...