Jump to content

Checking if next page is already loaded

Recommended Posts

Hi Guys, newbie here. Is there any better way to accomplish my goal here than what I came up with currently? Below is the code I made to check if the next page is ready and loaded. My situation is that page 1 has a captcha verification, after typing in the captcha and hitting submit the page goes to page 2 where the form filling starts. I made it so the Autoit script I'm running pauses at the captcha page then after typing the captcha I want Autoit to wait till the next page is ready (All texboxes are visible etch.) then continue running the rest of the script. The code below is inserted at the captcha page.
The code below does a while loop giving the user time to type the captcha. When the user is finished entering the captcha then hitting ENTER the page goes to page 2 where the user needs to fill some form. Page 2 contains a welcome message at the top that says "Welcome to page to. Please fill the form.". The code below exits the loop and continues with the rest of the scripts as soon as the welcome message is visible "Meaning page 2 is visible and ready.".
NOTE: How I did it before was pausing the script before the captcha then continuing the script after the captcha but that requires the user to press the hotkey for continue script. I am aiming for ease and convenience for the user so I want them to just type the captcha then hit enter and as soon as page 2 is visible the script should auto-continue, wouldn't want the user to have to press a button to continue the script.
;Captcha is visible at this point

While 1
   Local $CheckNextPageisready = _IEBodyReadText($oIE)
   Local $PositionCheck = StringInStr($CheckNextPageisready, "Welcome to page to. Please fill the form.")
   if $PositionCheck > 0 Then ExitLoop

;Continue running the script


Link to comment
Share on other sites

  • Moderators

Hmm, maybe try using a unique object type that doesn't exist on the captcha page (like a form) on the 2nd page, when that object exists, exit the loop and continue.

eg. (pseudo code):

Global $ghOIEWnd = Hwnd($oIE.hwnd)
Global $gszUniqueFormName = "formName"
Global $goForm = 0

; pause for captcha entering

While WinExists($ghOIEWnd) ; ensure the browser wasn't closed and us die forever in the loop
    $goForm = _IEFormGetObjByName($oIE, $gszUniqueFormName) ; find that unique object
    If IsObj($goForm) Then ExitLoop ; yay! our unique object is here so we're on page 2
    Sleep(50) ; rest the cpu

; verify browser isn't closed
If Not WinExists($ghOIEWnd) Then
    MsgBox(16 + 262144, "Error", "Browser was closed unexpectedly!")
    Exit 101

_IELoadWait($oIE) ; ensure the page is completely loaded before we continue

; We have our form object and we are on page 2
; Rest of code below


Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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

  • Recently Browsing   0 members

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