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.

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

Hello @GregEisenberg You need to do this: Local $oJsonRect=_WD_ElementAction($sSession, $sElements, 'rect') ConsoleWrite("!" & Json_Get($oJsonRect, "[x]") & @CRLF) ConsoleWr

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 mLipok
      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.


      Regards,
      @mLipok
       
    • 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/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      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/205553-webdriver-udf-help-support-iii/
      Previous support threads (Closed)
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By Hermes
      I have Index.html where it contains a frame with a source "frame1.html". I can select/highlight elements in index.html but unable to select/highlight elements inside the frame with the src "frame1.html", the autoit output is throwing error:
      __WD_Post: URL=HTTP://127.0.0.1:9515/session/2143396006437be4005db3b84acc1496/element/8be1c3c4-5bb1-42b1-8cde-7954765cbc61/element; $sData={"using":"css selector","value":"frameset:nth-of-type(1)"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\... __WD_Post ==> No match: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"frameset:nth-of-type(1)\"}\n (Session info: chrome=90.0.4430.212)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00FCE7D3+124883]\n\tOrdinal0 [0x00FCE7B1+124849]\n\tGetHandleVerifier [0x01218688+193832]\n\tGetHandleVerifier [0x0123C478+340760]\n\tGetHandleVerifier [0x012361F1+315537]\n\tGetHandleVerifier [0x012516BA+427354]\n\tGetHandleVerifier [0x01236176+315414]\n\tGetHandleVerifier [0x0125174A+427498]\n\tGetHandleVerifier [0x0125D6EB+476555]\n\tGetHandleVerifier [0x0125154B+426987]\n\tGetHandleVerifier [0x01234FFD+310941]\n\tGetHandleVerifier [0x01235D8E+314414]\n\tGetHandleVerifier [0x01235D19+314297]\n\tGetHandleVerifier [0x012F31EC+1089676]\n\tGetHandleVerifier [0x012F17C9+1082985]\n\tGetHandleVerifier [0x012F13A3+1081923]\n\tGetHandleVerifier [0x013ED9FD+2115741]\n\tOrdinal0 [0x0111B82E+1488942]\n\tOrdinal0 [0x010B5A7D+1071741]\n\tOrdinal0 [0x010B559B+1070491]\n\tOrdinal0 [0x010B54B1+1070257]\n\tOrdinal0 [0x010EFF53+1310547]\n\tBaseThreadInitThunk [0x770662C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B34+1028]\n"}} Auto IT Script:
      #Include "wd_core.au3" #Include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'index.html') _WD_LoadWait($sSession) Local $index = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)") Local $index1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index) Local $index2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frame:nth-of-type(1)", $index1) Local $index3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index2) _WD_HighlightElement($sSession, $index2, 1) _WD_HighlightElement($sSession, $index3, 1) _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":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome  

      frame1.html index.html
    • By Hermes
      Hi, sometimes when I run my script in GUI (SciTe Editor) or as an executable file, the chrome driver launches but the chrome browser does not but when I re-run the script again - chrome driver launches and so does the browser. Here is the error that I'm getting:
      __WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver... __WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver _WD_CreateSession: WinHTTP request timed out before Webdriver _WD_CreateSession ==> Webdriver Exception: HTTP status = 0 Just wondering if there's a way to re-launch both the driver and browser without having to rerun the script/executable.
       
       
    • By SkysLastChance
      I am using web driver and xpaths to automate chrome. 
      I am able to edit everything I need to until I get these pop ups. Then when I try to find the xpath it act like it does not exist. 
      This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it. 😕
      $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']") _WD_ElementAction($sSession, $sElement, 'value', "TEST") Here is the html

      Any idea why it is not finding the element inside these pop overs?
       
       
      HTML:
       
×
×
  • Create New...