Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

Danp2, thanks again for your help
The working version of the line looks like this:

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "' &$b&'"],"log": {"level": "trace"}}}}}'

I’ll no longer risk asking about random browser behavior, although I really want to know :-)

Thank you!

Link to comment
Share on other sites

Hello again,
I got a problem connecting to open sessions:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Schedule
            For $i = 1 to 2 Step 1
                $p = 2827 + $i
                $b = 'C:/4studio/FFProfiles/Bot'&$i
                SGLoop()
                _WD_Startup()
                $sSession = _WD_CreateSession($sDesiredCapabilities)
                _WD_Navigate($sSession, "https://2ip.ru")
            Next
        Case $Now
            For $i = 1 to 2 Step 1
                $p = 2827 + $i
                $b = 'C:/4studio/FFProfiles/Bot'&$i
                urlins()
            Next
    EndSwitch
WEnd

Func urlins()
    SGLoop()
    _WD_Startup()
    _WD_Option('DriverParams', '--connect-existing')
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, "https://test.com/login/")
EndFunc
Func SGLoop()
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)
    _WD_Option('DriverParams', '--marionette-port ' & $p)
    $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "' &$b&'"],"log": {"level": "trace"}}}}}'
EndFunc

The first button Case $Schedule, I open the browser window and a link to https: //2ip.ru Everything opens normally.
The second button Case $Now, I try in open sessions to change the link to test.com
And here there is a problem, firefox constantly issues a request to close the browser window. He wants to complete the running process to open a new window!
Although the link in the open windows changes ....

What am I doing wrong?

P.S. I apologize for the importunity.

Edited by sarge
Link to comment
Share on other sites

A couple of issues I can see --

  • You should make all calls to _WD_Option before calling _WD_Startup
  • You need to combine your attempts to set DriverParams to a single call to _WD_Option, like this --
    _WD_Option('DriverParams', '--log trace --connect-existing --marionette-port ' & $p)

Also, can you explain why you chose this implementation? Did you considered saving the Session IDs to an array and then reusing them from there?

Link to comment
Share on other sites

Fixed it:

Func urlins()
    SGLoop()
    _WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, "https://test.com/login/")
EndFunc
Func SGLoop()
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('Port', 4444)
    _WD_Option('DriverParams', '--log trace --marionette-port ' & $p)
    $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "' &$b&'"],"log": {"level": "trace"}}}}}'
EndFunc

When a button Case $Now is pressed, the urlins() function is called.

In this function, function SGLoop is first executed, in which all parameters _WD_Option are registered before _WD_Startup.

But without result 😞

Regarding the introduction of the array, this is a great idea, but unfortunately I'm not too experienced in autoit, if you give a link to an example, I will do just that.

 

Link to comment
Share on other sites

v0.2.0.8 just released with the following changes --

    - Fixed: Error handling in _WD_IsLatestRelease
    - Changed: Add support for DriverClose option to _WD_Option
    - Changed: _WD_Startup no longer closes existing driver consoles if DriverClose option (_WD_Option) is False
    - Changed: Add support for HTTPTimeouts option to _WD_Option
    - Changed: Set timeouts for WinHTTP requests if HTTPTimeouts option (_WD_Option) is True

Link to comment
Share on other sites

v0.2.0.9 just released with the following changes --

    - Changed: _WD_Status now returns Dictionary object instead of raw JSON string
    - Changed: Add support for DebugTrim option to _WD_Option
    - Changed: Remove check for $HTTP_STATUS_SERVER_ERROR (chromedriver relic)
    - Changed: Improved output from _WD_IsLatestRelease
    - Fixed: Default arguments for _WD_ExecuteScript should be empty string
    - Fixed: Removed unneeded string conversion
    - Added: Generic error detection routine

All primary functions will now detect additional errors, such as Invalid Session ($WD_InvalidSession)

P.S. Let me know if you encounter any issues with the generic error checking routine I added.

Edited by Danp2
Link to comment
Share on other sites

  • 2 weeks later...

v0.3.0.1 just released with the following changes --

    - Changed (_WD_Window): Add support for New option
    - Changed (_WD_Window): Add support for Print option
    - Changed (_WD_Window): Window option can now be used to switch tabs (ala existing 'switch' option)
    - Added: Unknown Command error detection

Link to comment
Share on other sites

_WD_WaitElement($sSession, $_WD_LOCATOR_ByXpath, "//input[@name='example']")

If @error = $_WD_ERROR_Timeout Then
    MsgBox(0, "", "Timeout")
Else
    MsgBox(0, "", "Example form loaded")
EndIf

How correctly check that form loaded after 5 sec and if no then try again (5 sec). like a two tryies before send timeout button?

I'm confused with $iDelay = Default, $iTimeout = Default...

Link to comment
Share on other sites

20 minutes ago, Danp2 said:

@auitden Check out the first few lines of code for the function and that should reveal how the parameter defaults are handled when they are omitted or equal to the Default keyword.

Why do you need to make two attempts for 5 secs each instead of a single attempt for 10 secs?

Because I don't understand what i doing. I want something like a max waiting time, for example: set param to 10 sec, if form loaded after 2 sec - ok, if 5 sec, but if after 10 sec form not loaded - timeout error, For ideally I want this) But not understand how i can setup it.

 

_WD_WaitElement($sSession, $_WD_LOCATOR_ByXpath, "//input[@name='example']", 2500, 10000)

4 attempts with 2,5 sec checking (10 sec max waiting time before exit), correctly?

Link to comment
Share on other sites

The current default wait is 10 secs, so all you need to do is provide the first few parameters --

_WD_WaitElement($sSession, $_WD_LOCATOR_ByXpath, "//input[@name='example']")

This will internally loop and continually check for the designated element. If it isn't found within those 10 secs, then it will return with @error set to _WD_ERROR_Timeout. If you use the $iDelay parameter, this delay only occurs once, before the initial search occurs.

Link to comment
Share on other sites

  • 2 weeks later...

@yeison1412 You can suppress the messages from popping up by placing the following near the top of your script --

$_WD_ERROR_MSGBOX = False

Note: This doesn't eliminate the error. It just prevents the messages from being shown.

My wild guess would be that the webdriver executable is missing on the new pc, but no way to know for sure what the issue is with the limited details you've provided this far.

 

Link to comment
Share on other sites

Hace 2 horas, yeison1412 dijo:

ERROR.PNG.0e93a6ad25dea495363636271279a01a.PNG

Saludos a todos, tengo un problema al ejecutar un bot compilado de autoit, que se realizó en otra PC donde funcionó bien, moví el bot a otra PC y recibo una serie de errores relacionados con WD_CORE, ¿cómo debo proceder?

 

Este es un código que encontré en Internet para iniciar el control de Chrome, pero me envía un conjunto de errores. Falta algo en el incluye? y también tengo el controlador de Chrome de acuerdo con la versión de mi Chrome

code.PNG

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21
  • Melba23 pinned this topic

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