Sign in to follow this  
Followers 0
Chimp

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

14 posts in this topic

#1 ·  Posted (edited)

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

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

just faster fingers ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

ok, thanks for answers

well... how to wait until a specific object exists on a new page?
 for example a form


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

Share this post


Link to post
Share on other sites

Use _IEGetObjById in a loop while @error = 7


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

well, many thanks water & danwilli for showing me the direction,
i will try in that way
bye


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

Share this post


Link to post
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


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

Share this post


Link to post
Share on other sites

It's possible that this error is due to the page reloading during the call to the _IEFrame* function. Did you try it using _IEGetObjById as suggested by water?

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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


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

Share this post


Link to post
Share on other sites

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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


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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  
Followers 0