#include "wd_helper.au3" #include "wd_capabilities.au3" #include #include Global $exeFF = "C:/Program Files (x86)/Mozilla Firefox/firefox.exe" Global $FFCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true, "moz:firefoxOptions": {"binary":"' & $exeFF & '", "args": ["about:blank"]}}}}' Example() Func Example() Local $hGUI = GUICreate("Example",400,400) GUICtrlCreateGroup("Normal", 20, 20, 200, 150) Local $idNormalModewikiJV = GUICtrlCreateButton("WIKIPEDIA Jules Verne", 50, 50, 150, 25) Local $idNormalModewikiVH = GUICtrlCreateButton("WIKIPEDIA Victor Hugo", 50, 100, 150, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Existing window", 20, 200, 200, 150) Local $idExistingWindowModewikiMG = GUICtrlCreateButton("WIKIPEDIA mahatma gandhi", 50, 230, 150, 25) Local $idExistingWindowModewikiWC = GUICtrlCreateButton("WIKIPEDIA winston churchill", 50, 280, 150, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) ; Affiche l'interface graphique. GUISetState(@SW_SHOW, $hGUI) While 1 $Msg = GUIGetMsg() Switch $Msg Case $idExistingWindowModewikiMG goToWikipedia("mahatma gandhi", false) Case $idExistingWindowModewikiWC goToWikipedia("winston churchill", false) Case $idNormalModewikiJV goToWikipedia("Jules Verne") Case $idNormalModewikiVH goToWikipedia("Victor Hugo") Case $GUI_EVENT_CLOSE exit EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example func launch_NormalMode($url) _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 4444) ;~ _WD_Option('DriverDetect', false) _WD_Startup() If @error <> $_WD_ERROR_Success Then MsgBox(0, "error1", "error1") exit EndIf $w_Session = _WD_CreateSession($FFCapabilities) If @error <> $_WD_ERROR_Success Then MsgBox(0, "error2", "error2") exit EndIf Sleep(500) _WD_Navigate($w_Session, $url) if @error Then msgbox ($MB_TOPMOST, "error3", "error3") exit EndIf Local $aHandles = _WD_Window($w_Session, 'handles') $handleApp = $aHandles[0] _WD_Window($w_Session, 'Switch', '{"handle":"' & $handleApp & '"}') return $w_Session EndFunc func launch_ExistingWindow($url) _WD_Option('Driver', 'geckodriver.exe') _WD_Option('Port', 4444) ;~ _WD_Option('DriverDetect', true) _WD_Option('DriverParams', '--log trace --marionette-port 2828') _WD_Startup() If @error <> $_WD_ERROR_Success Then MsgBox(0, "error1", "error1") exit EndIf $w_Session = _WD_CreateSession($FFCapabilities) If @error <> $_WD_ERROR_Success Then MsgBox(0, "error2", "error2") exit EndIf Sleep(500) _WD_Navigate($w_Session, $url) if @error Then msgbox ($MB_TOPMOST, "error3", "error3") exit EndIf Local $aHandles = _WD_Window($w_Session, 'handles') $handleApp = $aHandles[0] _WD_Window($w_Session, 'Switch', '{"handle":"' & $handleApp & '"}') return $w_Session EndFunc func goToWikipedia($param, $normalMode = Default) ConsoleWrite(@CRLF&@CRLF) If $normalMode = Default Then $normalMode = true If ($normalMode) Then ConsoleWrite("NORMAL MODE"&@CRLF) $session = launch_NormalMode("https://eu.wikipedia.org/") Else ConsoleWrite("EXISTING WINDOW MODE"&@CRLF) $session = launch_ExistingWindow("https://eu.wikipedia.org/") EndIf $w_temp = 0 $r = -99 while $w_temp < 10000 $w_ch = _WD_FindElement($session, $_WD_LOCATOR_ByXPath, "//*[@id='searchInput']") if @error = 0 Then $r = $w_ch ExitLoop Else sleep(300) $w_temp = $w_temp + 300 EndIf WEnd if $r = -99 Then msgbox($MB_TOPMOST, "error", "_WD_FindElement error") EndIf _WD_ElementAction($session, $r, 'value', $param) Sleep(1000) Send("{ENTER}") _WD_Shutdown() EndFunc