Jump to content

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


Danp2
 Share

Recommended Posts

Hello guys,

first of all thank you for this awesome udf.

if you want to use it in backround, here is what i use to hide the windows:

I know its ugly code, but its easy to rewrite if you want to.

I'm currently also trying to implement it into an embedded stance - if i accomplish it, I will share it here.

Maybe this can be included in the UDF - i tried with different chrome windows open, just hides the correct one and the driver each time.

global $pid
    $pid = _WD_Startup()
If @error <> $_WD_ERROR_Success Then
    _exit()
EndIf
Func _hidewindows()
    ;hide chromium
    $chromium_pid_2 =  _GETWINDOWFROMPID($pid)
    WinSetState($chromium_pid_2, "", @SW_HIDE )
    ;hide chrome
    $test = WinList("[REGEXPTITLE:(?i)(.*data:.*)]")
    If IsArray($test) Then
        For $i = 1 To $test[0][0]
            ConsoleWrite( @CRLF&@CRLF& "!-"&$i&" title: "&$test[$i][0]&@CRLF&@CRLF )
        Next
        WinSetState($test[1][0], "", @SW_HIDE)
    EndIf
EndFunc
Func _GETWINDOWFROMPID($PID)
    $HWND = 0
    $STPID = DllStructCreate("int")
    Do
        $WINLIST2 = WinList()
        For $I = 1 To $WINLIST2[0][0]
            If $WINLIST2[$I][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $WINLIST2[$I][1], "ptr", DllStructGetPtr($STPID))
                If DllStructGetData($STPID, 1) = $PID Then
                    $HWND = $WINLIST2[$I][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $HWND <> 0
    Return $HWND
EndFunc   ;==>GETWINDOWFROMPID

 

Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

4 hours ago, Busti said:

Hello, does this also remove the chrome driver window?

No, that's accomplished by settting $_WD_DEBUG equal to $_WD_DEBUG_None

5 hours ago, Busti said:

And do you mean headless by adding an "args": argument?

Yes, I believe that's correct. If you search the forum there are a few examples of this (either this thread or the H&S one.

Link to comment
Share on other sites

13 hours ago, Danp2 said:

No, that's accomplished by settting $_WD_DEBUG equal to $_WD_DEBUG_None

Yes, I believe that's correct. If you search the forum there are a few examples of this (either this thread or the H&S one.

Oh, thank you - i did not know about this.

 

Is this changeable in the runtime?

Because if not, i think i  would still prefer the method where i can decide if i want the windows to be shown or hidden.

 

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

@Busti I wrote this the other day based on our discussion. Please test it and let me know how it works for you.

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_ConsoleVisible
; Description ...: Control visibility of the webdriver console app
; Syntax ........: _WD_ConsoleVisible([$lVisible = False])
; Parameters ....: $lVisible            - [optional] Set to true to hide the console
; Return values .: None
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_ConsoleVisible($lVisible = False)
    Local $sFile = StringRegExpReplace($_WD_DRIVER, "^.*\\(.*)$", "$1")
    Local $pid, $pid2, $hWnd = 0

    $pid = ProcessExists($sFile)

    If $pid Then
        $aWinList=WinList("[CLASS:ConsoleWindowClass]")

        For $i=1 To $aWinList[0][0]
            $pid2 = WinGetProcess($aWinList[$i][1])

            If $pid2 = $pid Then
                $hWnd=$aWinList[$i][1]
                ExitLoop
            EndIf
        Next

        If $hWnd<>0 Then
            WinSetState($hWnd, "", $lVisible ? @SW_SHOW : @SW_HIDE)
        EndIf
    EndIf

EndFunc   ;==>_WD_ConsoleVisible

 

Link to comment
Share on other sites

Hello,

Nice work, thank you.

You have an invisible typo in this text:

"C:\Users\ataltambanis\Desktop\Autoit 3\Projekte\EVGA Admin Tools\includes\tool_includes\pid_functions.au3"(31,51) : error: syntax error (illegal character)
    Local $sFile = StringRegExpReplace($_WD_DRIVERï <-----

After removing it, it works like a charm.

Thank you.

 

Do you want to include an option to hide the browser window aswell?

 

Also, there tons of capabilities etc. for the browsers.

Wouldn't it be possible, to create some constants with all of them, like Global Const $__CHROME_KIOSK = "-- kiosk" or something like that - and also an function for the users, to edit the capabilites with those static variables?

Would be realy nice - if its already included, then i'm, dumb and forget what I just said :)

But anyway i highly appreciate your work, its very nice.

Right now im trying to figure out the POST and GET with it - and if its possible - cause it would ease some things.

I also feel like the use of "Tabs" is not very comfortable in my opinion and maybe you have an idea to make then more user friendly or let tabs work side by side.

Or create a let the user create "manual tabs" in which they could manually interact with.

Also, i did not find an option for hiding a tab - which gets automated  - and the other one (for example) are for the user to do things manually.

I'm not sure if this is even possible but i highly think, if somebody knows the answer here, it could be you :)

Again thanks for your work, effort & support - its great.

 

Edit:

rewrote half of the text, dunno whats going on with my english right now.

 

Edit:

btw. this was my test implementation which instantly workd out:

Func _hidewindows()
    _WD_ConsoleVisible(False)
    #cs
    $chromium_driver_title = WinList("[REGEXPTITLE:(?i)(.*chromedriver.*)]")
    $chromium_driver = _WD_Option("Driver")
    $chromium_pid = ProcessExists($chromium_driver)
    ConsoleWrite( @CRLF&@CRLF& "! HIDDEN CHROME WINDOW: "&$chromium_driver_title& " - "&$chromium_pid&@CRLF&@CRLF )
        $chromium_pid_2 =  _GETWINDOWFROMPID($pid)
    $chromium_pid_3 = $pid
    $chromium_pid_4 = _GETWINDOWFROMPID($chromium_pid_3)
    WinSetState($chromium_pid_2, "", @SW_HIDE )
    ConsoleWrite( @CRLF&@CRLF& "! HIDDEN CHROMIUM DRIVER "& $chromium_pid_2 & " - " & $chromium_pid & " - " & $chromium_pid_3 & " - " & $chromium_pid_4 &  @CRLF&@CRLF )
    #ce
        $test = WinList("[REGEXPTITLE:(?i)(.*data:.*)]")
    If IsArray($test) Then
        For $i = 1 To $test[0][0]
            ConsoleWrite( @CRLF&@CRLF& "!-"&$i&" title: "&$test[$i][0]&@CRLF&@CRLF )
        Next
            WinSetState($test[1][0], "", @SW_HIDE)
    EndIf
EndFunc
Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

5 minutes ago, Busti said:

You have an invisible typo in this text:

Not sure where that came from because it doesn't occur on my end, but glad you were able to quickly resolve it. :thumbsup:

7 minutes ago, Busti said:

Do you want to include an option to hide the browser window aswell?

Also, there tons of capabilities etc. for the browsers, why you don create some constants with all of them, like Global Const $__CHROME_KIOSK = "-- kiosk" or something like that and also an function for the users, to edit the capabilites with those static variables?

Not on my radar screen at the moment. 😉 My goal was to keep the UDF as browser "independent" as possible. As such, I wouldn't want to place these constants in one of the existing files. I guess we could look at creating an optional include file that would contain these.

Link to comment
Share on other sites

Sounds great, because this awesomeness of an UDF should really be continued and also expanded.

It still is Browser independed, that wouldnt change by adding more functionality, it would just increase the amount of work you would have to put it :)

[also i need (for chromedriver as example) chrome installed on my system, otherwise it won't work for me - or I'm doing smt. wrong?)

I will try and add some bad implementations on my own and post them here, maybe i can bait you :D

 

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

2 minutes ago, Busti said:

[also i need (for chromedriver as example) chrome installed on my system, otherwise it won't work for me - or I'm doing smt. wrong?)

Not sure what you mean here.

2 minutes ago, Busti said:

I will try and add some bad implementations on my own and post them here, maybe i can bait you :D

Ha Ha

Link to comment
Share on other sites

Well, for example i had Chrome 74 installed on my system, but was using chromdriver 73.

It told me to upgrade the driver because it is not compatible with chrome 74.

Which makes me think it wouldn't work without chrome, as it seems like to require an installation of chrome to be functional?

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

Just now, Danp2 said:

@Busti

1) You can't automate a browser that isn't installed

2) The webdriver version needs to "match" the installed browser version

Okay, ye - that's what my conclusion was. But thank you for confirming that.

I just though, maybe theres a Chrome light version packed into the driver, who knows - is possible to day, but yes - the file would be far bigger then.

So i just didn't think it to the end. :)

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

Guys,


Can you please advise, how I can use the new Function _WD_jQuerify for the WebDriver UDF?
I was using the _jQuerify Function with IE before, but now I want to switch to Chrome, with the Web Driver.

 

The issue I have is, that when I don't know how to make the following with the _WD_jQuerify Function in WD:

    $jQuery('#manager_manager_id').append("<option value=" & $parentAccountID & " selected>" & $parentAccount & "</option>")
    $jQuery('#manager_manager_id').trigger('change')

The above was working as expected using IE and _jQuerify

 

For _WD_jQuerify I have tried the following:

 Local $script = 'jQuery("#manager_manager_id").append(<option value=' & $parentAccountID & ' selected>' & $parentAccount & '</option>'
_WD_ExecuteScript($sSession, $script)

Sleep(500)

Local $script = '("#manager_manager_id").trigger("change")'
_WD_ExecuteScript($sSession, $script)

 

I have also tried different approaches, but it seems all are wrong :(

 

When I use the above, the page is getting broken and it is not selecting(Appending) anything in the Select2 dropdown menu I want to hit.
 

Your assistance guys is much appreciated.

 

Thank you,
Milen

Link to comment
Share on other sites

8 minutes ago, MilenP said:

 Local $script = 'jQuery("#manager_manager_id").append(<option value=' & $parentAccountID & ' selected>' & $parentAccount & '</option>' _WD_ExecuteScript($sSession, $script)

@MilenP You appear to be on the right track. Can you post the results from the Scite output panel?

Edit: Here's a prior example I posted

 

Edited by Danp2
Link to comment
Share on other sites

@Danp2,

Part of the Result in the Output panel related to this is:

__WD_Post: URL=HTTP://127.0.0.1:9515/session/5313af6deb7ac982d0be4497c2c560e2/execute/async; $sData={"script":"(function(jqueryUrl, callback) {    if (typeof jqueryUrl != 'string') {        jqueryUrl = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';    }    if (typeof jQuery == 'undefined') {        var script = document.createElement('script');        var head = document.getElementsByTagName('head')[0];        var done = false;        script.onload = script.onreadystatechange = (function() {            if (!done && (!this.readyState || this.readyState == 'loaded'                     || this.readyState == 'complete')) {                done = true;                script.onload = script.onreadystatechange = null;                head.removeChild(script);                callback();            }        });        script.src = jqueryUrl;        head.appendChild(script);    }    else {        jQuery.noConflict();        callback();    }})(arguments[0], arguments[arguments.length - 1]);", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/5313af6deb7ac982d0be4497c2c560e2/execute/sync; $sData={"script":"jQuery", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/5313af6deb7ac982d0be4497c2c560e2/execute/sync; $sData={"script":"jQuery", "args":[("#manager_manager_id").append(<option value=4001 selected>Production</option>]}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_ExecuteScript: missing command parameters
__WD_Post: URL=HTTP://127.0.0.1:9515/session/5313af6deb7ac982d0be4497c2c560e2/execute/sync; $sData={"script":"jQuery", "args":[("#manager_manager_id").trigger("change")]}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_ExecuteScript: missing command parameters

Please let me know if you think that I should provide you more of the log.

 

Thank you,

Milen

Link to comment
Share on other sites

The above one was with a different test I made, the below is actually different, but the error is the same :)
 

__WD_Post: URL=HTTP://127.0.0.1:9515/session/a68bc89b9bc39517ea2aa733b7b82e7d/execute/async; $sData={"script":"(function(jqueryUrl, callback) {    if (typeof jqueryUrl != 'string') {        jqueryUrl = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js';    }    if (typeof jQuery == 'undefined') {        var script = document.createElement('script');        var head = document.getElementsByTagName('head')[0];        var done = false;        script.onload = script.onreadystatechange = (function() {            if (!done && (!this.readyState || this.readyState == 'loaded'                     || this.readyState == 'complete')) {                done = true;                script.onload = script.onreadystatechange = null;                head.removeChild(script);                callback();            }        });        script.src = jqueryUrl;        head.appendChild(script);    }    else {        jQuery.noConflict();        callback();    }})(arguments[0], arguments[arguments.length - 1]);", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/a68bc89b9bc39517ea2aa733b7b82e7d/execute/sync; $sData={"script":"jQuery", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/a68bc89b9bc39517ea2aa733b7b82e7d/execute/sync; $sData={"script":"jQuery("#manager_manager_id").append(<option value=4001 selected>Production</option>", "args":[[]]}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_ExecuteScript: missing command parameters
__WD_Post: URL=HTTP://127.0.0.1:9515/session/a68bc89b9bc39517ea2aa733b7b82e7d/execute/sync; $sData={"script":"jQuery("#manager_manager_id").trigger("change")", "args":[[]]}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_ExecuteScript: missing command parameters

 

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