Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

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

@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
On 9/22/2018 at 10:52 PM, Danp2 said:

@ngocthang26 Have you tried it like this? Note that the proxy definition is outside of chromeOptions.

$sDesiredCapabilities = '{"capabilities":{"chromeOptions": {"w3c": "true"},"browserName": "chrome", "args": ["disable-web-security"], "proxy": {"proxyType":"manual","httpProxy":"10.179.70.127:10801","sslProxy":"10.179.70.127:10801","autodetect": "false"}}}'

Also, is that your actual IP address for the proxy or just something you pulled off the internet?

Hi Danp 2, thanks you reply

Edited by ngocthang26
Thanks

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • 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/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
    • By Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
    • By JohnWIlling
      We are running on a VIrtual Machine via Remote Desktop.  We are having a situation where the loading of the chromedriver.exe is taking longer on the VM than on a physical machine.  It is causing the first call to  WD_Post in _WD_CreateSession to fail.
      To workaround the Issue, I used a simplified version of (_WinAPI_GetTcpTable) UDF to Loop waiting for the driver port to be in the listening state.  At that point, I know that the Post will work:
      Func _WaitForPort($ListenPort) Do Local $tMIB_TCPTABLE = DllStructCreate("dword[6]") Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True) Local $dwSize = $aRet[2] $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]") $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True) If $aRet[0] <> 0 Then Return SetError(1) Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1) Local $aRes[$iNumEntries][6] For $i = 0 To $iNumEntries - 1 Local $Type = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0) $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port Local $Port = $aRet[0] ConsoleWrite("Checking Row:" & $i & " State:<" & $Type & "> Port:<" & $Port & ">" & @CRLF) ; Type 2 is LISTENING If $Type = 2 And $Port = $ListenPort Then Return 1; EndIF Next Sleep(500); Until 0; Return 0; EndFunc ;==>_WaitForPort  
×
×
  • Create New...