Jump to content

Recommended Posts

Hi all, 

 

I´m trying to use the command "WD_LoadWait" because I want to pause the script until the web page fully loads in Firefox but I don´t know how to use it.

Here´s the full help

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_LoadWait
; Description ...: Wait for a browser page load to complete before returning
; Syntax ........: _WD_LoadWait($sSession[, $iDelay = 0[, $iTimeout = -1[, $sElement = '']]])
; Parameters ....: $sSession - Session ID from _WDCreateSession
; $iDelay - [optional] Milliseconds to wait before checking status
; $iTimeout - [optional] Period of time to wait before exiting function
; $sElement - [optional] Element ID to confirm DOM invalidation
; Return values .: Success - 1
; Failure - 0 and sets the @error flag to non-zero
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_LoadWait($sSession, $iDelay = Default, $iTimeout = Default, $sElement = Default)
Local Const $sFuncName = "_WD_LoadWait"
Local $iErr, $sResponse, $oJSON, $sReadyState
 
If $iDelay = Default Then $iDelay = 0
If $iTimeout = Default Then $iTimeout = $_WD_DefaultTimeout
If $sElement = Default Then $sElement = ""
 
If $iDelay Then Sleep($iDelay)
 
Local $hLoadWaitTimer = TimerInit()
 
While True
If $sElement <> '' Then
_WD_ElementAction($sSession, $sElement, 'name')
 
If $_WD_HTTPRESULT = $HTTP_STATUS_NOT_FOUND Then $sElement = ''
Else
$sResponse = _WD_ExecuteScript($sSession, 'return document.readyState', '')
$iErr = @error
 
If $iErr Then
ExitLoop
EndIf
 
$oJSON = Json_Decode($sResponse)
$sReadyState = Json_Get($oJSON, "[value]")
 
If $sReadyState = 'complete' Then ExitLoop
EndIf
 
If (TimerDiff($hLoadWaitTimer) > $iTimeout) Then
$iErr = $_WD_ERROR_Timeout
ExitLoop
EndIf
 
Sleep(100)
WEnd
 
If $iErr Then
Return SetError(__WD_Error($sFuncName, $iErr, ""), 0, 0)
EndIf
 
Return SetError($_WD_ERROR_Success, 0, 1)

EndFunc

 

Any sugestions or examples?

Link to comment
Share on other sites

Hi Picorico2 and welcome!

First, when we post code we use the button that looks like this: <>  on the forum post editor.

Second, what do you mean you don't know how to use it? Have you installed a driver for your browser? Does _WD_CreateSession work? Do you not understand the _WD_LoadWait parameters? (Being a little more specific goes a long way)

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
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Thanks for the early reply,

 

Its an honor that the creator of the Web Driver has answered me.

 

I just want to open a web page, and pause the script until it fully loads.

 

and do I have to use the line below (I'm a newbie)

 

$sSession = _WD_CreateSession($sDesiredCapabilities)

Please post an example.

 

Link to comment
Share on other sites

After creating the session, you can then navigate to the desired site using _WD_Navigate. Next you would call _WD_LoadWait. Something like this --

_WD_Navigate($sSession, "http://google.com")
_WD_LoadWait($sSession)

_WD_LoadWait offers several optional parameters. Look at the function header for a description of what action each one performs. Try writing some code to "practice" using these optional features. Then come back and let us know how you fared. :thumbsup:

Link to comment
Share on other sites

Good Morning Danp2,

 

I got an error that says that I haven´t declared the variable so I copied the line below from your demo but still doesn´t do anything

 

Local $sDesiredCapabilities, $iIndex, $sSession

 

Here's the code:

#include "wd_core.au3"
#include "wd_helper.au3"
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Local $sDesiredCapabilities, $iIndex, $sSession

_WD_Navigate($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/indexMs.php")

_WD_LoadWait($sSession)

 

Like I said I´m a newbie but I want to learn, pls be patient. 😄

 

 

 

Link to comment
Share on other sites

I would really suggest taking a look at wd_demo.au3 that comes with the UDF. You're looking for something a bit more like this: (untested)

#include <MsgBoxConstants.au3>
#include <wd_core.au3>
#include <wd_helper.au3>

; Here you can specify some browser specific settings... you'll need to research them depending on your browser
; ... or just copy paste someone else's code :D

#Region Settings Setup
  _WD_Option('Driver', 'geckodriver.exe')
  _WD_Option('DriverParams', '--log trace')
  _WD_Option('Port', 4444)

  Global $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
#EndRegion Settings Setup

; You need to initialize some stuff with this UDF
_WD_Startup()
; If there is an error setting stuff up, then exit
If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

; Create a new instance of a browser with some settings you request
Global $sSession = _WD_CreateSession($sDesiredCapabilities)
; If there was an error, exit
If Not (@error = $_WD_ERROR_Success) Then Exit MsgBox($MB_ICONERROR, "Error: _WD_CreateSession", "Failed to create a Session. Check your desired capabilities.")

; Move to the requested website
_WD_Navigate($sSession, "http://yourwebsite.com")

; Anything you want to do after navigating to the website goes here
MsgBox($MB_ICONINFORMATION, "Navigation completed!", "Click ok to shutdown the browser and console")

; This removes the browser instance
_WD_DeleteSession($sSession)

; And this cleans up some resources
_WD_Shutdown()

Edit 1: Updated with Gecko driver settings... didn't realize that was used for FireFox
Edit 2: _WD_Options goes before _WD_Startup

Edited by seadoggie01

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
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Did you download the geckodriver? If yes: Is it located in your script's directory, or did you properly specify the location of it?

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
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

My apologies, a little dyslexia going on there... _WD_Options goes first, then _WD_Startup... I'll edit my post

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
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Hi there again,

Now for some unknown reason it has stopped working

It doesn´t open the web page anymore and continues the script.

Here's my code:

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <MsgBoxConstants.au3>
#include <wd_core.au3>
#include <wd_helper.au3>
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{Esc}", "ExitScript")

$_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error

; Here you can specify some browser specific settings... you'll need to research them depending on your browser
; ... or just copy paste someone else's code :D

#Region Settings Setup
_WD_Option('Driver', 'C:\Program Files (x86)\AutoIt3\Include\geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

Global $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
#EndRegion Settings Setup

; You need to initialize some stuff with this UDF
_WD_Startup()
; If there is an error setting stuff up, then exit
If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

; Create a new instance of a browser with some settings you request
;Global $sSession = _WD_CreateSession($sDesiredCapabilities)
; If there was an error, exit
;If Not (@error = $_WD_ERROR_Success) Then Exit MsgBox($MB_ICONERROR, "Error: _WD_CreateSession", "Failed to create a Session. Check your desired capabilities.")


Local $sDestination = "E:\Documentos\AUTOIT\palomitav.jpg"

Local $sDesiredCapabilities, $iIndex, $sSession

;Verificar si la serie es correcta

MsgBox($MB_SYSTEMMODAL, "Serie", "Favor de copiar la serie y dar clic en Aceptar")

SplashTextOn("", "Verificando la serie en Pago Referenciado...", 200, 60, 1400, 5, 600, 60, opt = 1)
; Ancho_Ven, Alto_Ven        Y,

Send("^{TAB}")

_WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/indexMs.php")

Send("{TAB 3}")
Sleep(1000)
Send("{ENTER}")

_WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/menuOper.php")

MouseMove(1047, 115, 5)
MouseMove(1047, 145, 5)
MouseMove(1223, 145, 5)
MouseMove(1223, 170, 5)
MouseClick("left")

_WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/PagoTenencia/tenencia2015/admin.php")

Send("{TAB}")
Send("^v")
MouseMove(404, 224, 5)
MouseClick("left")

SplashOff()

$a = MsgBox(4, "", "¿Es correcta la serie?")

If $a = 6 Then ;SI

    ;MouseMove(309, 476, 5)
    ;MouseClick("left")
    Send("{TAB 6}")
    ;Sleep(500)
    Send("{DOWN 3}")
    Send("{TAB}")
    Send("{ENTER}")

    Send("{TAB}")
    Send("{ENTER}")

    _WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/PagoTenencia/tenencia2015/index.php?i=3&usu=570&serie=8AFDR5ADXA6284122&sid=0.29255510000995255")

    Send("{END}")

ElseIf $a = 7 Then ;NO

    Send("^+{TAB}")

    MsgBox($MB_SYSTEMMODAL, "Placa", "Favor de copiar la PLACA y dar clic en Aceptar")

    Send("^{TAB}")

    MouseMove(425, 226, 5)
    MouseClick("left")

    Sleep(1000)
    Send("{TAB}")
    Send("^v")
    Sleep(10000)

    $a = MsgBox(4, "", "¿Es correcta la placa?")

    If $a = 6 Then ;SI

        MouseMove(95, 295, 5)
        MouseClick("left")
        MouseMove(404, 224, 5)
        MouseClick("left")
        MouseMove(309, 517, 5)
        MouseClick("left")
        Sleep(1000)
        Send("{DOWN 3}")
        Send("{ENTER}")
        Sleep(1000)
        Send("{TAB}")
        Send("{ENTER}")
        Sleep(1000)
        Send("{TAB 2}")
        Send("{ENTER}")
        Sleep(4000)
        Send("{END}")

    ElseIf $a = 7 Then ;NO

        ;WinActivate ("Cobro de Tenencia ::: Sistema Pago Referenciado - Mozilla Firefox")

        Sleep(1000)

        Send("^+{TAB}")

        Send("r")

        Sleep(3000)

        Send("El número de serie y placa son incorrectos")

    EndIf

EndIf

Func ExitScript()
    Exit
EndFunc   ;==>ExitScript

 

 

 

Link to comment
Share on other sites

@picorico2

Please read:

and this:

https://www.autoitscript.com/wiki/Forum_FAQ#How_can_I_post_.22code.22_on_the_forum_.3F

also:
https://www.autoitscript.com/wiki/Forum_FAQ#How_can_I_edit_my_post_on_the_forum_.3F

so I propose you to edit your post because the code you posted is not posted well (is not formated).

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <MsgBoxConstants.au3>
#include <wd_core.au3>
#include <wd_helper.au3>
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

HotKeySet("{Esc}", "ExitScript")

$_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error

; Here you can specify some browser specific settings... you'll need to research them depending on your browser
; ... or just copy paste someone else's code :D

#Region Settings Setup
_WD_Option('Driver', 'C:\Program Files (x86)\AutoIt3\Include\geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

Global $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
#EndRegion Settings Setup

; You need to initialize some stuff with this UDF
_WD_Startup()
; If there is an error setting stuff up, then exit
If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

; Create a new instance of a browser with some settings you request
;Global $sSession = _WD_CreateSession($sDesiredCapabilities)
; If there was an error, exit
;If Not (@error = $_WD_ERROR_Success) Then Exit MsgBox($MB_ICONERROR, "Error: _WD_CreateSession", "Failed to create a Session. Check your desired capabilities.")


Local $sDestination = "E:\Documentos\AUTOIT\palomitav.jpg"

Local $sDesiredCapabilities, $iIndex, $sSession

;Verificar si la serie es correcta

MsgBox($MB_SYSTEMMODAL, "Serie", "Favor de copiar la serie y dar clic en Aceptar")

SplashTextOn("", "Verificando la serie en Pago Referenciado...", 200, 60, 1400, 5, 600, 60, opt = 1)
; Ancho_Ven, Alto_Ven        Y,

Send("^{TAB}")

_WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/indexMs.php")

Send("{TAB 3}")
Sleep(1000)
Send("{ENTER}")

_WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/menuOper.php")

MouseMove(1047, 115, 5)
MouseMove(1047, 145, 5)
MouseMove(1223, 145, 5)
MouseMove(1223, 170, 5)
MouseClick("left")

_WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/PagoTenencia/tenencia2015/admin.php")

Send("{TAB}")
Send("^v")
MouseMove(404, 224, 5)
MouseClick("left")

SplashOff()

$a = MsgBox(4, "", "¿Es correcta la serie?")

If $a = 6 Then ;SI

    ;MouseMove(309, 476, 5)
    ;MouseClick("left")
    Send("{TAB 6}")
    ;Sleep(500)
    Send("{DOWN 3}")
    Send("{TAB}")
    Send("{ENTER}")

    Send("{TAB}")
    Send("{ENTER}")

    _WD_LoadWait($sSession, "https://guerrero.gob.mx/Pry_PagoReferenciado/Administracion/PagoTenencia/tenencia2015/index.php?i=3&usu=570&serie=8AFDR5ADXA6284122&sid=0.29255510000995255")

    Send("{END}")

ElseIf $a = 7 Then ;NO

    Send("^+{TAB}")

    MsgBox($MB_SYSTEMMODAL, "Placa", "Favor de copiar la PLACA y dar clic en Aceptar")

    Send("^{TAB}")

    MouseMove(425, 226, 5)
    MouseClick("left")

    Sleep(1000)
    Send("{TAB}")
    Send("^v")
    Sleep(10000)

    $a = MsgBox(4, "", "¿Es correcta la placa?")

    If $a = 6 Then ;SI

        MouseMove(95, 295, 5)
        MouseClick("left")
        MouseMove(404, 224, 5)
        MouseClick("left")
        MouseMove(309, 517, 5)
        MouseClick("left")
        Sleep(1000)
        Send("{DOWN 3}")
        Send("{ENTER}")
        Sleep(1000)
        Send("{TAB}")
        Send("{ENTER}")
        Sleep(1000)
        Send("{TAB 2}")
        Send("{ENTER}")
        Sleep(4000)
        Send("{END}")

    ElseIf $a = 7 Then ;NO

        ;WinActivate ("Cobro de Tenencia ::: Sistema Pago Referenciado - Mozilla Firefox")

        Sleep(1000)

        Send("^+{TAB}")

        Send("r")

        Sleep(3000)

        Send("El número de serie y placa son incorrectos")

    EndIf

EndIf

Func ExitScript()
    Exit
EndFunc   ;==>ExitScript

 

Link to comment
Share on other sites

While you are in "debugging mode", I would recommend removing the line where you modify $_WD_DEBUG. That way, you get the greatest level of feedback in the Scite console panel. Also, it looks like you've commented out the line containing _WD_CreateSession, so that would explain why the browser is no longer being launched.

Finally, be careful with your variable declarations. I see where you are declaring some variables as Global and then redeclaring them as Local ($sDesiredCapabilities for example).

Link to comment
Share on other sites

Ok. I removed the debugging mode. I commented out the line containing the _WD_CreateSession because I don´t want to open a new Firefox Windows, I just want to move to the next tab on the right, open a web site, wait for it to finish loading and move on, and finally I don´t undertand about variables and declarations :(  pls help me to fix the code, and also can you tell me what´s the meaning of "DesiredCapabilities" sound funny to me. English is not my first language.

The main reason I want to use Webdrive is because sometimes the web site I´m trying to access in Firefox takes longer to completely load than usual so if I use "Sleep" is not very accurate.

Thank you kindly.

 

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

×
×
  • Create New...