Jump to content

Recommended Posts

Posted (edited)

Not something that I've tried, but this is how I would approach it --

  • _WD_Startup returns the PID of the webdriver console
  • Obtain an array of child processes by calling _WinAPI_EnumChildProcess with this PID
  • Find the desired browser instance within this array

Edit: It's even easier with Firefox. Just grab the value associated with "moz:processID" from $_WD_SESSION_DETAILS, which contains the JSON response from the webdriver when the session was created.

Edited by Danp2
Posted
; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_GetBrowserPID
; Description ...: Get browser PID
; Syntax ........: _WD_GetBrowserPID($iPID, $sBrowserName)
; Parameters ....: $iPID                - WebDriver PID returned by _WD_Startup()
;                  $sBrowserName        - [optional] Browser name from the list of supported browsers ($_WD_SupportedBrowsers)
; Return values .: Success - Browser PID
;                  Failure - "" and sets @error to one of the following values:
;                  - $_WD_ERROR_NotFound
;                  - $_WD_ERROR_NotSupported
;                  - $_WD_ERROR_NoMatch
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_GetBrowserPID($iPID, $sBrowserName = '')
    Local $aProcessList = _WinAPI_EnumChildProcess($iPID)
    If @error Then Return SetError($_WD_ERROR_NotFound, 0, '')

    Local $iIndex = _ArraySearch($_WD_SupportedBrowsers, $sBrowserName, Default, Default, Default, Default, Default, $_WD_BROWSER_Name)
    If @error Then Return SetError($_WD_ERROR_NotSupported, 0, '')

    If $sBrowserName = '' Then _
            Return $aProcessList[1][0]

    Local $sBrowserExe = $_WD_SupportedBrowsers[$iIndex][$_WD_BROWSER_ExeName]
    For $i = 1 To $aProcessList[0][0]
        If $aProcessList[$i][1] = $sBrowserExe Then
            Return $aProcessList[$i][0]
        EndIf
    Next

    Return SetError($_WD_ERROR_NoMatch, @extended, '')
EndFunc   ;==>_WD_GetBrowserPID


WARNING: not tested

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

 

  On 6/1/2022 at 7:34 PM, Danp2 said:

Are you sure that you are running the most recent UDF version?

Expand  

I have 0.9.0 - should be the right one but sorry my question was wrong.

I have used    _WD_GetBrowserVersion("msedgedriver.exe") to get the driver version before I have startet it. And that returns since 01.06.2022 EdgeDrv:Edge before EdgeDrv:101.0.1210.53.

So it is not the browser version, but the driver version that doesn't work. Is there another way?

Posted (edited)

_WD_GetWebDriverVersion($sWebdriverPath, "msedgedriver.exe") = "Edge" 

Have you tried this with V 102.0.1245.30 ?

Local $sOutput="Microsoft Edge WebDriver 102.0.1245.30 (8f49f1a4740db8559bf9e49b4a7b6c754f80250d)"
Local $aMatches = StringRegExp($sOutput, "\s+([^\s]+)", 1)
_ArrayDisplay($aMatches)

image.png.0d8e0865e9ae21032526c9222637639e.png

There must be something wrong with StringRegExp().

And found it: up to the last version of msedgedriver the result was 

MSEdgeDriver 101.0.1210.53 (019dbf6dd738aa1846d87f5734878db0ee9df370) - so just one word before the version. Now there are three words 😉

 

Edited by HJL
Posted
  On 6/3/2022 at 11:52 AM, Danp2 said:

@mLipokWhy go to the trouble of writing the function, but not test it before posting? 🙄

P.S. It doesn't work correctly when a browser name isn't supplied

Expand  

I started doing this function because it was on my TODO list, a client called and I had to stop working on this function.
But I wanted to share what I had.

Meanwhile, I have finished my work.
Please check here: https://github.com/Danp2/au3WebDriver/pull/324

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

When something is on github letit stay there ;)

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 06/04/2022
Posted (edited)

I have an issue with using _WD_ExecuteScript() on FF but it works on Chrome.

Here is my testing script

#include "wd_helper.au3"
#include "wd_capabilities.au3"

_Example()

Func _Example()
    Local $sCapabilities = SetupGecko(False)
;~  Local $sCapabilities = SetupChrome(False)
    _WD_Startup()
    Local $sSession = _WD_CreateSession($sCapabilities)

    _WD_Navigate($sSession, 'https://ezamowienia.gov.pl/mo-client-board/bzp/list')

    MsgBox(0, "", 'wait')

    Local $s_Date = '2021/01/01'
    Local $s_JAVA_Script = _
            "var fp = flatpickr('#lib-date-0', {});" & _
            "fp.setDate( new Date('" & $s_Date & "'),true);" & _
            ""

    ConsoleWrite("! " & $s_JAVA_Script & @CRLF)

    _WD_ExecuteScript($sSession, $s_JAVA_Script)

EndFunc

Func SetupGecko($bHeadless)
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)

;~  Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'firefox')
    _WD_CapabilitiesAdd('browserName', 'firefox')
    _WD_CapabilitiesAdd('acceptInsecureCerts', True)
    If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless')
    _WD_CapabilitiesDump(@ScriptLineNumber) ; dump current Capabilities setting to console - only for testing in this demo
    Local $sCapabilities = _WD_CapabilitiesGet()
    Return $sCapabilities
EndFunc   ;==>SetupGecko

Func SetupChrome($bHeadless)
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

;~  Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"]}}}}'
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless')
    _WD_CapabilitiesDump(@ScriptLineNumber) ; dump current Capabilities setting to console - only for testing in this demo
    Local $sCapabilities = _WD_CapabilitiesGet()
    Return $sCapabilities
EndFunc   ;==>SetupChrome

 

Can anybody explain to me why it did not work on FF ?
 

Edited by mLipok

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

No errors. Just in firefox date is not set in date picker element.

Edited by mLipok

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

From the FF Dev console --

  Quote
Expand  

From the Chrome Dev console --

  Quote


main-es2015.94dd897f12f5e4f68c3c.js:1 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'dateFormat')
TypeError: Cannot read properties of undefined (reading 'dateFormat')
    at A.n.setDate (main-es2015.94dd897f12f5e4f68c3c.js:1:1730336)
    at e.writeValue (main-es2015.94dd897f12f5e4f68c3c.js:1:1322534)
    at main-es2015.94dd897f12f5e4f68c3c.js:1:1400090
    at main-es2015.94dd897f12f5e4f68c3c.js:1:1408269
    at Array.forEach (<anonymous>)
    at pe.setValue (main-es2015.94dd897f12f5e4f68c3c.js:1:1408258)
    at main-es2015.94dd897f12f5e4f68c3c.js:1:1421287
    at l.invoke (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:6624)
    at Object.onInvoke (main-es2015.94dd897f12f5e4f68c3c.js:1:894304)
    at l.invoke (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:6564)
    at T (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:12196)
    at polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:13024
    at l.invokeTask (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:7242)
    at Object.onInvokeTask (main-es2015.94dd897f12f5e4f68c3c.js:1:894193)
    at l.invokeTask (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:7163)
    at i.runTask (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:2651)
    at m (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:9236)
    at u.invokeTask [as invoke] (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:8321)
    at p (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:20575)
    at HTMLInputElement.f (polyfills-es2015.8a706b3d5d3a4ffdb557.js:1:20820)

Expand  

Haven't researched any further than this, but I suspect you are not calling the function with the correct parameters since both browsers are returning an error.

Edited by Danp2
Posted

@mLipokThe following works for me in both Chrome and Firefox (both still show some errors in the browser console) --

Local $s_Date = '2021/06/10'
    Local $s_JAVA_Script = _
            "var fp = flatpickr('#lib-date-0', {});" & _
            "fp.setDate('" & $s_Date & "',true,'Y/m/d');" & _
            ""
    _WD_ExecuteScript($sSession, $s_JAVA_Script)

 

Posted

Thanks @Danp2 
It works.
How did you handle this ?

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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