Jump to content

WebDriver UDF - Help & Support


Recommended Posts

  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is the "General Help and Support" thread for the WebDriver UDF. The UDF itself can be downloaded here. So if you have any questions, suggestions or errors please post here.

use the _WD_ElementAction function like this: $sValue = _WD_ElementAction($sSession, $sElement, 'attribute', 'src') p.s. ... and remove @src from the xPath: "//img[@alt='NiceGirl']"

Time ago I wrote a function to extract data from  the source HTML code of tables. https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Seems that that fun

Posted Images

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


 

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

 

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

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

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?

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

 

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
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
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 TTE26
      For the past two days I've been reading all Wiki pages, installed all the demos etc. but I am still unable to do this simple workflow
      1. I want to use WebDriver UDF to open Chrome (Set chrome option arguments - Window Size, Pixel ratio, device type and platform name, user-agent.)
      2. On new Tab I want to read the tab Title and save it into a TXT file.
      3. I need to save the Session ID with my previosly set Capabilities into a file.
      4. I want to close the chrome window.
      Then
      5. I want to open Chrome again, but with my previosly saved Session ID and Capabilities list from the file.
      6. And minimaze the window state.
      7. After 30 seconds, close the chrome.
      I would really appreciate for the WebDriver UDF Helper file, to have also basic code examples, for non coders. For example how to open a windwow etc., save sessions, etc.
      Anyway, if someone could help me get started and help me with this workflow, that would be much appreaciated. 😔
    • By lapoelkan12
      hi i try to use webdriver  i download it and  download json and  winhttp i try to run it  but  return error
       error: __WinHttpVer(): undefined function.
              Local $sWinHttpVer = __WinHttpVer()
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
       
       

    • By levila
      Hi Guys, i just do some codding to automate login to some of the web.
      I manage to do the script but somehow after script done, some weird box popup. and keep looping until i close the main chrome.exe

      here is my code. kinldy pls assist, im very new to webdriver udf.
      #NoTrayIcon #include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://someoftheweb.com") _ChromeSetInputValueByName($sSession, "inputName", "Username") _ChromeSetInputValueById($sSession, "inputPassword", "Password") _ChromeSetMouseClick($sSession, "submit", "click") _WD_Shutdown() 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, "args":["--no-sandbox"]}}}}' EndFunc Func _ChromeSetInputValueByName($sSession,$name,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$name&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetMouseClick($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@type='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click', $Value) EndFunc  
    • By RohanM
      Hi Team,
      is there is a way to embed the webpage in auto it GUI using webdriver? what I want to do is that, I want to open edge browser inside the AutoIT GUI, in IE we have _IECreateEmbedded function but for the webdriver I am not able to find a function, please help  
      Rohan M
    • By goku200
      I am trying to change the settings of the print option to Save as PDF and its not changing the settings and clicking on the Save button at the bottom. Here is my script that I have written and the format is correct below. Chrome browser I'm using is 97.0 My script was working fine using Chrome 95.0\ Not sure why its not working now
      It finds the print-preview-app element but not the others.
       
×
×
  • Create New...