#include "wd_core.au3" #include "wd_helper.au3" Local Enum $eFireFox = 0, _ $eChrome Local Const $_TestType = $eChrome Local $sDesiredCapabilities Local $iIndex Local $sSession $_WD_DEBUG = $_WD_DEBUG_Info Switch $_TestType Case $eFireFox CloseBrowser("FireFox") SetupGecko() Case $eChrome CloseBrowser("Chrome") SetupChrome() EndSwitch _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep(1000) ;~ msgbox(0, "", $sSession) ;~ DemoElements() Demo_Elements_2() ;~ DemoActions() ;~ _WD_DeleteSession($sSession) ;~ _WD_Shutdown() Func DemoTimeouts() _WD_Timeouts($sSession) _WD_Timeouts($sSession, '{"pageLoad":2000}') _WD_Timeouts($sSession) EndFunc ;==>DemoTimeouts Func DemoNavigation() _WD_Navigate($sSession, "http://google.com") ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF) _WD_Action($sSession, "back") ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF) _WD_Action($sSession, "forward") ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF) ConsoleWrite("Title=" & _WD_Action($sSession, 'title') & @CRLF) EndFunc ;==>DemoNavigation Func DemoElements() Local $sElement, $aElements, $sValue _WD_Navigate($sSession, "http://google.com") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='tsf']/div[2]/div/div[1]/div/div[1]/input") If @error = $_WD_ERROR_NoMatch Then msgbox(0, "NO MATCH", "KO") EndIf _WD_ElementAction($sSession, $sElement, 'click') _WD_ElementAction($sSession, $sElement, 'value', "My Test works") Sleep(500) $buttonsearch = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='tsf']/div[2]/div[3]/center/input[1]") _WD_ElementAction($sSession, $buttonsearch, 'click') Print($sValue) MsgBox(0, "TEST FINISHED", "OK") EndFunc ;==>DemoElements Func Demo_Elements_2() Local $sElement, $aElements, $sValues $UrlFile = "file:///" & stringreplace(@ScriptDir, "\", "/") & "/test.html" _WD_Navigate($sSession, $UrlFile) _WD_Window($sSession, "maximize") _WD_LoadWait($sSession, "", "", "") ; Expected Result The table is highlighted yellow rounded box + border dotted red $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/table") _WD_HighlightElements($sSession, $aElements, 3) ;~ _ArrayDisplay($aElements) _ArrayDisplay(_WD_GetTableContent($sSession, "/html/body/table", "##")) EndFunc ;==>Demo_Elements_2 ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func _WD_GetTableContent($sSession, $aElements, $Separator) Local $BaseElement Local $LineNumber Local $ColNumber Local $i local $j Local $sValue Local $TmpValue $BaseElement = $aElements $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $BaseElement & "/tbody/tr", "", True) $LineNumber = Ubound($aElements) $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $BaseElement & "/tbody/tr[1]/td", "", True) $ColNumber = Ubound($aElements) Local $sArray = [$LineNumber] $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $BaseElement & "/tbody/tr/td", "", True) ;~ _ArrayDisplay($aElements) $CellNumber = Ubound($aElements) For $i = 0 To $CellNumber - 1 $sElement = $aElements[$i] $TmpValue = _WD_ElementAction($sSession, $sElement, 'Text') $sValue = $sValue & $Separator & $TmpValue $j = $j + 1 If $j = $ColNumber Then ;~ Debug($sValue) $sValue = StringMid($sValue,2) _ArrayAdd($sArray,$sValue) $sValue = "" $j = "" Endif Next Return $sArray EndFunc ;==>_WD_GetTableContent ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func DemoScript() _WD_ExecuteScript($sSession, "return arguments[0].second;", '{"first": "1st", "second": "2nd", "third": "3rd"}') _WD_Alert($sSession, 'Dismiss') EndFunc ;==>DemoScript ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func DemoCookies() _WD_Navigate($sSession, "http://google.com") _WD_Cookies($sSession, 'Get', 'NID') EndFunc ;==>DemoCookies ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func DemoAlerts() ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF) _WD_ExecuteScript($sSession, "alert('testing 123')") ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF) ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF) _WD_Alert($sSession, 'sendtext', 'new text') ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF) Sleep(5000) _WD_Alert($sSession, 'Dismiss') EndFunc ;==>DemoAlerts ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func DemoFrames() _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols") ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF) ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']") ; _WD_Window($sSession, "frame", '{"id":{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}}') _WD_FrameEnter($sSession, $sElement) ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF) _WD_FrameLeave($sSession) ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF) EndFunc ;==>DemoFrames ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func DemoActions() Local $sElement, $aElements, $sValue _WD_Navigate($sSession, "http://google.com") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//input[@id="lst-ib"]') ConsoleWrite("$sElement = " & $sElement & @CRLF) $sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"' $sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}' ConsoleWrite("$sAction = " & $sAction & @CRLF) _WD_Action($sSession, "actions", $sAction) sleep(5000) _WD_Action($sSession, "actions") sleep(5000) EndFunc ;==>DemoActions ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('DriverParams', '--log trace') _WD_Option('Port', 4444) $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}' EndFunc ;==>SetupGecko ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}' EndFunc ;==>SetupChrome ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func Print($Value) ConsoleWrite($Value & @CRLF) EndFunc ;==>Print ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func Debug($Value) ConsoleWrite($Value & @CRLF) InputBox("Debug", $Value, $Value) EndFunc ;==>Debug ;___________________________________________________________________________________________________________________________________________________________________________________________________________________________ Func CloseBrowser($BrowserName) While ProcessExists($BrowserName & ".EXE") ProcessClose($BrowserName & ".EXE") WEnd EndFunc ;==>CloseBrowser