Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

this is 

_
WD_ElementAction($sSession, $Upload, 'click')

That is not accepted. Only a click on left or right button of the mouse is accepted. Is it possible with elementAction to do something ?

Share this post


Link to post
Share on other sites

It's impossible to use autoit automation because the programm blocks on this instruction

$Upload = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='files[]' and @id='inputFile']")
$sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $Upload & '"}'
$sResponse = _WD_ExecuteScript($sSession, "return arguments[0].click()", $sJsonElement)

Here is the debug log 

__WD_Post: URL=HTTP://127.0.0.1:17556/session/1D4582A5-9360-41BA-8230-44A5E63F2259/element; $sData={"using":"xpath","value":"//input[@name='files[]' and @id='inputFile']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"2b5201cf-8262-43f0-bead-d6bc308d54af","element-6066-11e4-a52e-4f735466cecf":"2b5201cf-8262-43f0-bead-d6bc308d54af"}}
_WD_FindElement: {"value":{"ELEMENT":"2b5201cf-8262-43f0-bead-d6bc308d54af","element-6066-11e4-a52e-4f735466cecf":"2b5201cf-8262-43f0-bead-d6bc308d54af"}}
_WD_WaitElement ==> Success
__WD_Post: URL=HTTP://127.0.0.1:17556/session/1D4582A5-9360-41BA-8230-44A5E63F2259/element; $sData={"using":"xpath","value":"//input[@name='files[]' and @id='inputFile']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"2b5201cf-8262-43f0-bead-d6bc308d54af","element-6066-11e4-a52e-4f735466cecf":"2b5201cf-8262-43f0-bead-d6bc308d54af"}}
_WD_FindElement: {"value":{"ELEMENT":"2b5201cf-8262-43f0-bead-d6bc308d54af","element-6066-11e4-a52e-4f735466cecf":"2b5201cf-8262-43f0-bead-d6bc308d54af"}}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/1D4582A5-9360-41BA-8230-44A5E63F2259/execute/sync; $sData={"script":"return arguments[0].click()", "args":[{"element-6066-11e4-a52e-4f735466cecf":"2b5201cf-8262-43f0-bead-d6bc308d54af"}]}
__WD_Post: StatusCode=0; ResponseText=0
__WD_Post ==> Send / Recv error
_WD_ExecuteScript: 0


 

Share this post


Link to post
Share on other sites

OK i download the  winhttp v 1.6.4.2

But the programm block on the window OpenFiledialog. It seems that's this window is modal.

Share this post


Link to post
Share on other sites

@loulou2522 Please try this code and report back (you'll need to modify the filename variable for your environment) --

#include "wd_core.au3"

Local $sDesiredCapabilities
Local $iIndex
Local $sSession
Local $sFilename = 'c:\DBAR_Ver2.txt'

;SetupGecko()
SetupChrome()

_WD_Startup()

$_WD_ESCAPE_CHARS = '\\"'

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://cgi-lib.berkeley.edu/ex/fup.html")
_WD_SelectUploadFile($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='upfile']",$sFilename)


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

$sDesiredCapabilities = '{"capabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }, "goog:loggingPrefs": {"browser":"ALL"}}}}'
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_SelectUploadFile
; Description ...:
; Syntax ........: _WD_SelectUploadFile($sSession, $sStrategy, $sSelector, $sFilename)
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sStrategy           - Locator strategy. See defined constant $_WD_LOCATOR_* for allowed values
;                  $sSelector           - Value to find
;                  $sFilename           - String representing full path of file to upload
; Return values .: Success      - 1
;                  Failure      - 0
;                  @ERROR       - $_WD_ERROR_Success
;                               - $_WD_ERROR_Exception
;                               - $_WD_ERROR_NoMatch
;                  @EXTENDED    - WinHTTP status code
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_SelectUploadFile($sSession, $sStrategy, $sSelector, $sFilename)
    Local Const $sFuncName = "_WD_SelectUploadFile"

    Local $sResponse, $sResult, $sJsonElement, $oJson
    Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector)
    Local $iErr = @error

    If $iErr = $_WD_ERROR_Success Then
        $sResult = _WD_ElementAction($sSession, $sElement, 'value', $sFilename)
        $iErr = @error

        If $iErr = $_WD_ERROR_Success Then
            $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
            $sResponse  = _WD_ExecuteScript($sSession, "return arguments[0].files.length", $sJsonElement)
            $oJson = Json_Decode($sResponse)
            $sResult  = Json_Get($oJson, "[value]")
        EndIf
    EndIf

    If $_WD_DEBUG = $_WD_DEBUG_Info Then
        ConsoleWrite($sFuncName & ': ' & $sResult & " file(s) selected" & @CRLF)
    EndIf

    Return SetError(__WD_Error($sFuncName, $iErr), $_WD_HTTPRESULT, $sResult)
EndFunc

 

Share this post


Link to post
Share on other sites

Hi Damp

Here is the result of your programm

_WDStartup: OS:    WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.21
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="C:\Users\Patrick\Desktop\TESTPOSTFINANCE\ChromeDriver\chrome.log"
_WDStartup: Port:    9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }, "goog:loggingPrefs": {"browser":"ALL"}}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"78.0.3904.97","chrome":{"chromedriverVersion":"78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800})","userDataDir":"C:\\Users\\Patrick\\AppData\\Local\\Temp\\scoped_dir15260_1274292444"},"goog:chromeOptions":{"debuggerAddress":"localhost:50840"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"81ba15e5ec9e04f3c1e0996579f7803f"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"78.0.3904.97","chrome":{"chromedriverVersion":"78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800})","userDataDir":"C:\\Users\\Patrick\\AppData\\Local\\Temp\\scoped_dir15260_1274292444"},"goog:chromeOptions":{"debuggerAddress":"localhost:50840"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"81ba15e5ec9e04f3c1e0996579f7803f"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/81ba15e5ec9e04f3c1e0996579f7803f/url; $sData={"url":"https://cgi-lib.berkeley.edu/ex/fup.html"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/81ba15e5ec9e04f3c1e0996579f7803f/element; $sData={"using":"xpath","value":"//input[@name='upfile']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"4bb969f7-1bba-4b0e-b717-ef3e8aa263bb"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"4bb969f7-1bba-4b0e-b717-ef3e8aa263bb"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/81ba15e5ec9e04f3c1e0996579f7803f/element/4bb969f7-1bba-4b0e-b717-ef3e8aa263bb/value; $sData={"id":"4bb969f7-1bba-4b0e-b717-ef3e8aa263bb", "text":"C:\\Users\\Patrick\\Desktop\\CV.EXEMPT.TXT"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/81ba15e5ec9e04f3c1e0996579f7803f/execute/sync; $sData={"script":"return arguments[0].files.length", "args":[{"element-6066-11e4-a52e-4f735466cecf":"4bb969f7-1bba-4b0e-b717-ef3e8aa263bb"}]}
__WD_Post: StatusCode=200; ResponseText={"value":1}
_WD_ExecuteScript: {"value":1}
_WD_SelectUploadFile: 1 file(s) selected
_WD_SelectUploadFile ==> Success
+>08:23:27 AutoIt3.exe ended.rc:0
+>08:23:27 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 10.05

And integrating in my programm

_WDStartup: WD.au3:    0.1.0.21
_WDStartup: Driver:    MicrosoftWebDriver.exe
_WDStartup: Params:    --verbose
_WDStartup: Port:    17556
__WD_Post: URL=HTTP://127.0.0.1:17556/session; $sData={"capabilities":{}}
__WD_Post: StatusCode=200; ResponseText={"value":{"sessionId":"7CED8404-8F06-45BF-9DF3-DC06A3EB80D3","capabilities":{"acceptInsecureCerts":false,"browserName":"MicrosoftEdge","browserVersion":"44.18362.387.0","pageLoadStrategy":"normal","platformName":"windows","setWindowRect":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"proxy":{}}}}
_WD_CreateSession: {"value":{"sessionId":"7CED8404-8F06-45BF-9DF3-DC06A3EB80D3","capabilities":{"acceptInsecureCerts":false,"browserName":"MicrosoftEdge","browserVersion":"44.18362.387.0","pageLoadStrategy":"normal","platformName":"windows","setWindowRect":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"proxy":{}}}}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/window/maximize; $sData={}
__WD_Post: StatusCode=200; ResponseText={"value":{"height":744,"width":1382,"x":0,"y":0}}
_WD_Window: {"value":{"height":744,"width":1382,"x":0,"y":0}}...
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/url; $sData={"url":"https://isotest.postfinance.ch/corporates/login?locale=fr"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element; $sData={"using":"xpath","value":"//input[@id='username']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"4dccf855-4994-40dc-a7f1-1b42910a65e0","element-6066-11e4-a52e-4f735466cecf":"4dccf855-4994-40dc-a7f1-1b42910a65e0"}}
_WD_FindElement: {"value":{"ELEMENT":"4dccf855-4994-40dc-a7f1-1b42910a65e0","element-6066-11e4-a52e-4f735466cecf":"4dccf855-4994-40dc-a7f1-1b42910a65e0"}}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element/4dccf855-4994-40dc-a7f1-1b42910a65e0/value; $sData={"id":"4dccf855-4994-40dc-a7f1-1b42910a65e0", "text":"loulou2522"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element; $sData={"using":"xpath","value":"//input[@id='password']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"d3540a36-86bc-4fd9-95ba-5ae25ab14024","element-6066-11e4-a52e-4f735466cecf":"d3540a36-86bc-4fd9-95ba-5ae25ab14024"}}
_WD_FindElement: {"value":{"ELEMENT":"d3540a36-86bc-4fd9-95ba-5ae25ab14024","element-6066-11e4-a52e-4f735466cecf":"d3540a36-86bc-4fd9-95ba-5ae25ab14024"}}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element/d3540a36-86bc-4fd9-95ba-5ae25ab14024/value; $sData={"id":"d3540a36-86bc-4fd9-95ba-5ae25ab14024", "text":"Isabelle01#"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element; $sData={"using":"xpath","value":"//button[@id='action.login']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"d251ce1a-6e51-49d0-8673-1c6cde81a7c8","element-6066-11e4-a52e-4f735466cecf":"d251ce1a-6e51-49d0-8673-1c6cde81a7c8"}}
_WD_FindElement: {"value":{"ELEMENT":"d251ce1a-6e51-49d0-8673-1c6cde81a7c8","element-6066-11e4-a52e-4f735466cecf":"d251ce1a-6e51-49d0-8673-1c6cde81a7c8"}}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element/d251ce1a-6e51-49d0-8673-1c6cde81a7c8/click; $sData={"id":"d251ce1a-6e51-49d0-8673-1c6cde81a7c8"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element; $sData={"using":"xpath","value":"//input[@name='files[]' and @id='inputFile']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"ELEMENT":"9b213276-9aab-4f29-8539-cad63397390d","element-6066-11e4-a52e-4f735466cecf":"9b213276-9aab-4f29-8539-cad63397390d"}}
_WD_FindElement: {"value":{"ELEMENT":"9b213276-9aab-4f29-8539-cad63397390d","element-6066-11e4-a52e-4f735466cecf":"9b213276-9aab-4f29-8539-cad63397390d"}}
__WD_Post: URL=HTTP://127.0.0.1:17556/session/7CED8404-8F06-45BF-9DF3-DC06A3EB80D3/element/9b213276-9aab-4f29-8539-cad63397390d/value; $sData={"id":"9b213276-9aab-4f29-8539-cad63397390d", "text":"C:\inetpub\wwwroot\sepach\doc\TESTSWISSSEPAVIR.xml"}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"unknown error","message":"An unknown error occurred while processing the specified command.","stacktrace":""}}
_WD_ElementAction: {"value":{"error":"unknown error","message":"An unknown error occurred while processing the specifie...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"unknown error","message":"An unknown error occurred while processing the specified command.","stacktrace":""}}
_WD_SelectUploadFile:  file(s) selected
_WD_SelectUploadFile ==> Webdriver Exception
+>08:34:14 AutoIt3.exe ended.rc:0
+>08:34:14 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 21.93

The main difference is that in the web page cliicking on input file open the open dialog window.

if you want i will send you by separate email the programm because the access of this web page is protected ?

Thanks for your great help

Share this post


Link to post
Share on other sites
4 hours ago, loulou2522 said:

The main difference is that in the web page cliicking on input file open the open dialog window.

You didn't implement the solution I posted within your code. Please revise your code and then try again.

Hint: My version no longer clicks on the input element

Share this post


Link to post
Share on other sites

Here is your add-on to add to wd_core3

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_SelectUploadFile
; Description ...:
; Syntax ........: _WD_SelectUploadFile($sSession, $sStrategy, $sSelector, $sFilename)
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sStrategy           - Locator strategy. See defined constant $_WD_LOCATOR_* for allowed values
;                  $sSelector           - Value to find
;                  $sFilename           - String representing full path of file to upload
; Return values .: Success      - 1
;                  Failure      - 0
;                  @ERROR       - $_WD_ERROR_Success
;                               - $_WD_ERROR_Exception
;                               - $_WD_ERROR_NoMatch
;                  @EXTENDED    - WinHTTP status code
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_SelectUploadFile($sSession, $sStrategy, $sSelector, $sFilename)
    Local Const $sFuncName = "_WD_SelectUploadFile"

    Local $sResponse, $sResult, $sJsonElement, $oJson
    Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector)
    Local $iErr = @error

    If $iErr = $_WD_ERROR_Success Then
        $sResult = _WD_ElementAction($sSession, $sElement, 'value', $sFilename)
        $iErr = @error

        If $iErr = $_WD_ERROR_Success Then
            $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
            $sResponse  = _WD_ExecuteScript($sSession, "return arguments[0].files.length", $sJsonElement)
            $oJson = Json_Decode($sResponse)
            $sResult  = Json_Get($oJson, "[value]")
        EndIf
    EndIf

    If $_WD_DEBUG = $_WD_DEBUG_Info Then
        ConsoleWrite($sFuncName & ': ' & $sResult & " file(s) selected" & @CRLF)
    EndIf

    Return SetError(__WD_Error($sFuncName, $iErr), $_WD_HTTPRESULT, $sResult)
EndFunc

      I test all These  function, they  works with Chrome , Edge and Firefox all in the last version

Thanls to Damp for this excellent programm of automation , it's really a great add-ons

Share this post


Link to post
Share on other sites

Thanks for reporting back on your success. FWIW, this will be added to wd_helper (not wd_core) since it's not one of the "core" webdriver functions.

Also, the function name may change in the final version. Not sure about _WD_SelectUploadFile; Considering _WD_SelectFiles instead. Anyone else have suggestions?

Share this post


Link to post
Share on other sites

Several months ago I encountered a version mismatch error and I had to update my chromedriver manually. Ever since then it has become my habit to check the compatibility once in a while. I wish that Google would make the chromedriver updated automatically when the chrome browser is updated.

The following code checks if my chromedriver is compatible with my chrome browser and, if necessary, downloads a compatible chromedriver. I am planning to put this in a scheduled task so that I may not worry about version mismatch any more. Any suggestion for improvement would be welcome.

#include <IE.au3>
#include <InetConstants.au3>
#include <FileConstants.au3>
#include "wd_core.au3"
;#include <Array.au3>

$sChromeVersion = FileGetVersion("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
$sDriverVersion = ""
If FileExists(@ScriptDir & "\chromedriver.exe") Then ; chromedriver version cannot be retrieved by FileGetVersion()
    $_WD_DEBUG = $_WD_Debug_None
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args": ["headless"]}}}}'
    _WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_DeleteSession($sSession)
    _WD_Shutdown()

    $sLog = FileRead(@ScriptDir & "\chrome.log")
    $aLog = StringRegExp($sLog, "Starting ChromeDriver (.*) \(", 1)
    If Not IsArray($aLog) Then
        Exit
    EndIf
    $sDriverVersion = $aLog[0]
EndIf

;MsgBox(0,'Chromedriver', 'Chrome Version: ' & $sChromeVersion & @CRLF & 'Driver Version: ' & $sDriverVersion)

$oIE = _IECreate("https://sites.google.com/a/chromium.org/chromedriver/downloads", 0, 0, 1)
If @error Then Exit MsgBox(0, '', 'Cannot create an IE object. @error: '  & @error)
$sText = _IEBodyReadText($oIE)
_IEQuit($oIE)
If $sText = "" Then Exit MsgBox(0, '', 'Cannot read the body text. @error: '  & @error)
$aText = StringSplit($sText, @CRLF, 1)
;_ArrayDisplay($aText)

$sVersion = ""
For $i = 1 To $aText[0]
    If $aText[$i] = "Supports Chrome version " & Number($sChromeVersion) Then
        $sVersion = StringReplace($aText[$i-2], "ChromeDriver ", "")
        ExitLoop
    EndIf
Next

If $sDriverVersion = $sVersion Then
    MsgBox(0, 'Chromedriver', 'No need to update chromedriver!')
    Exit
EndIf

FileMove(@ScriptDir & "\chromedriver_win32.zip", @ScriptDir & "\chromedriver_win32_old.zip", $FC_OVERWRITE)
$sZipFile = @ScriptDir & "\chromedriver_win32.zip"
$iSize = InetGet("https://chromedriver.storage.googleapis.com/" & $sVersion & "/chromedriver_win32.zip", $sZipFile, $INET_FORCERELOAD, $INET_DOWNLOADWAIT)
;https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_win32.zip

If $iSize> 0 Then
    FileMove(@ScriptDir & "\chromedriver.exe", @ScriptDir & "\chromedriver_old.exe", $FC_OVERWRITE)
    $sDriverPath = @ScriptDir
    $oShell = ObjCreate ("Shell.Application")
    $FilesInZip = $oShell.NameSpace($sZipFile).items
    $oShell.NameSpace($sDriverPath).CopyHere($FilesInZip,0x4)
    MsgBox(0, 'Chromedriver', 'Chromedriver version ' & $sVersion & ' was installed.')
Else
    FileMove(@ScriptDir & "\chromedriver_win32_old.zip", @ScriptDir & "\chromedriver_win32.zip", $FC_OVERWRITE)
    MsgBox(0, 'Chromedriver', 'Download of chromedriver zip file failed.')
EndIf

 

Edited by CYCho

Share this post


Link to post
Share on other sites

@CYCho Here's an alternative method of getting the Chrome version details --

#include <Inet.au3>
#include <String.au3>

$sChromeVersion = FileGetVersion("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
ConsoleWrite("Chrome version - " & $sChromeVersion & @CRLF)

$iPID = Run(@ScriptDir & "\chromedriver.exe --version", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$sOutput = StdoutRead($iPID)
$aResult = _StringBetween($sOutput, "ChromeDriver ", " (")
$sChromeDriver = @error ? "" : $aResult[0]
ConsoleWrite("Chromedriver version -- " & $sChromeDriver & @CRLF)

$sChromeVersionShort = StringLeft($sChromeVersion, StringInStr($sChromeVersion, ".", 0, -1) - 1)
$sChromeDriverLatest = _INetGetSource("https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & $sChromeVersionShort)

ConsoleWrite("Chromedriver latest -- " & $sChromeDriverLatest & @CRLF)

If $sChromeDriver <> $sChromeDriverLatest Then
    ConsoleWrite("ChromeDriver upgrade needed!" & @CRLF)
EndIf

 

Share this post


Link to post
Share on other sites

@Danp2 Your knowledge and creativity always amazes me. I absolutley like your alternative method. My revised code here:

#include <Inet.au3>
#include <String.au3>

$sPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", "")
If @error Then Exit
$sChromeVersion = FileGetVersion($sPath)
ConsoleWrite("Chrome version - " & $sChromeVersion & @CRLF)

$iPID = Run(@ScriptDir & "\chromedriver.exe --version", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
ProcessWaitClose($iPID)
$sOutput = StdoutRead($iPID)
$aResult = _StringBetween($sOutput, "ChromeDriver ", " (")
$sChromeDriver = @error ? "" : $aResult[0]
ConsoleWrite("Chromedriver version -- " & $sChromeDriver & @CRLF)

$sChromeVersionShort = StringLeft($sChromeVersion, StringInStr($sChromeVersion, ".", 0, -1) - 1)
$sChromeDriverLatest = _INetGetSource("https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & $sChromeVersionShort)

ConsoleWrite("Chromedriver latest -- " & $sChromeDriverLatest & @CRLF)

If $sChromeDriver = $sChromeDriverLatest Then
    ConsoleWrite("ChromeDriver upgrade not needed!" & @CRLF)
    Exit
EndIf

FileMove(@ScriptDir & "\chromedriver_win32.zip", @ScriptDir & "\chromedriver_win32_old.zip", $FC_OVERWRITE)
$sZipFile = @ScriptDir & "\chromedriver_win32.zip"
$iSize = InetGet("https://chromedriver.storage.googleapis.com/" & $sChromeDriverLatest & "/chromedriver_win32.zip", $sZipFile, $INET_FORCERELOAD, $INET_DOWNLOADWAIT)
;https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_win32.zip

If $iSize > 0 Then
    FileMove(@ScriptDir & "\chromedriver.exe", @ScriptDir & "\chromedriver_old.exe", $FC_OVERWRITE)
    $sDriverPath = @ScriptDir
    $oShell = ObjCreate ("Shell.Application")
    $FilesInZip = $oShell.NameSpace($sZipFile).items
    $oShell.NameSpace($sDriverPath).CopyHere($FilesInZip,0x4)
    ConsoleWrite("Chromedriver version " & $sChromeDriverLatest & " was installed" & @CRLF)
Else
    FileMove(@ScriptDir & "\chromedriver_win32_old.zip", @ScriptDir & "\chromedriver_win32.zip", $FC_OVERWRITE)
    ConsoleWrite("Download of chromedriver zip file failed" & @CRLF)
EndIf

 

Edited by CYCho

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Similar Content

    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Function List
      Core Functions
      _WD_CreateSession($sDesiredCapabilities='{}') _WD_DeleteSession($sSession) _WD_Status() _WD_Timeouts($sSession, $sTimeouts = '') _WD_Navigate($sSession, $sURL) _WD_Action($sSession, $sCommand) _WD_Window($sSession, $sCommand, $sOption = '') _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False) _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='') _WD_ExecuteScript($sSession, $sScript, $sArguments="[]") _WD_Alert($sSession, $sCommand, $sOption = '') _WD_GetSource($sSession) _WD_Cookies($sSession, $sCommand, $sOption = '') _WD_Option($sOption, $vValue = "") _WD_Startup() _WD_Shutdown() Helper Functions
      _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "") _WD_Attach($sSession, $sString, $sMode = 'title') _WD_LinkClickByText($sSession, $sText, $lPartial = True) _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]]) _WD_GetMouseElement($sSession) _WD_GetElementFromPoint($sSession, $iX, $iY) _WD_LastHTTPResult() _WD_GetFrameCount() _WD_IsWindowTop() _WD_FrameEnter($sIndexOrID) _WD_FrameLeave() _WD_HighlightElement($sSession, $sElement[, $iMethod = 1]) _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession) WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ConsoleVisible($lVisible = False) _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1) Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
    • By Davidowicza
      Hey guys,
      I am creating my very first script that automates a browser (I usually work with program installs and database automation) and have come across an issue that I am totally stumped on. I need to click an element that gives me a drop down list box but the Xpath to the element changes with every instance of chrome I start...
      I have tried selecting the class, rect, and path but no luck. It never finds the element. (I could be doing this wrong since I am not good at HTML)
      Element I need to select:
      This is the Xpath for the last 3 instances of chrome I have run the script with:
      //*[@id="highcharts-5bp9crq-8"]/svg/g[6]/g/rect //*[@id="highcharts-fiw9szv-8"]/svg/g[6]/g/rect //*[@id="highcharts-5szkmx8-8"]/svg/g[6]/g/rect As you can see the path changes every time.
      How I am trying to select the element:
      ;Check for box element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") MsgBox(0, "", "check for timeout") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") _WD_ElementAction($sSession, $sElement, 'click') Maybe someone has come across this before and found a work around without using mouseclick()
      Thanks guys, hopefully I am just very overlooking something simple and can be pointed to the right solution.
      Side Note: I wish I could share the webpage entirety, but it has sensitive information with my agency that I cannot share. If you need more, just let me know and I will try and post as much as I can.
    • By daluu
      This is kind of already posted here:
      '?do=embed' frameborder='0' data-embedContent>>
      but wanted to note this in this forum of example scripts in case some people only look in this forum for examples and not the other forums with respect to AutoIt integration or relation to Selenium WebDriver.
      So, the example in summary is: you can use Selenium WebDriver API to do AutoIt GUI automation (the ControlXyz() and WinXyz() functons, along with mouse and "send keys" functions). Although I suppose that might be opposite or counter to what most examples here are about - using AutoIt to do or control other stuff rather than using other stuff to control/run AutoIt. But regardless, it is an example implementation of a different use case for AutoIt beyond the general AutoIt community, like those who also use Selenium WebDriver and/or need to integrate Selenium with AutoIt for remote deployment.
      https://github.com/daluu/AutoItDriverServer
      with specific demo examples here:
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/CalculatorTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/calculator.py
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
×
×
  • Create New...