#include-once #include ; #INDEX# ======================================================================================================================= ; Title .........: Firefox Developer Tools Automation UDF Library for AutoIt3 ; UDF Version : 0.2 ; AutoIt Version : 3.3.16.1 ; Language ......: English ; Description ...: A collection of functions for creating, attaching to and manipulating Firefox. ; Author(s) .....: autoitscript.com/forum/profile/108393-fraizor/ ; =============================================================================================================================== ;~ V0.2 ;~ Made the commusnication faster and smarter Func _AFPrepare($SW = @SW_HIDE) Local $Result ;Check if Firefox is installed If Not(FileExists(EnvGet("systemdrive") & "\Program Files\Mozilla Firefox\firefox.exe")) And Not(FileExists(EnvGet("systemdrive") & "\Program Files (x86)\Mozilla Firefox\firefox.exe")) Then $Result = 0 MsgBox(16, "Error", "Firefox not installed, Please install Firefox then try again..", 10) Else ;Firefox is installed ... ProcessClose("firefox.exe") ProcessWaitClose("firefox.exe", 10) WindowDevTools() ShellExecute("firefox.exe", "-devtools -foreground -new-window") WinWait("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]","", 10) $Result = WinSetState("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]","", $SW) EndIf EndFunc Func _AFLoad($URL) Return CommandSend("window.location.href = '" & $URL & "';") EndFunc Func _AFLoadWait($URL, $Timeout = 10) Local $Result CommandSend("window.location.href = '" & $URL & "';") Do Sleep(2500) $Result = CommandSend("document.title = document.readyState;") Until WinExists("[CLASS:MozillaWindowClass; TITLE:complete — Mozilla Firefox]") Return $Result EndFunc Func _AFAction($Action) Local $Result If $Action = "stop" Then $Result = CommandSend("window.stop();") ElseIf $Action = "refresh" Then $Result = CommandSend("window.location.href = '';") ElseIf $Action = "quit" Then $Result = ProcessClose("firefox.exe") ElseIf $Action = "back" Then $Result = CommandSend("history.back();") ElseIf $Action = "forward" Then $Result = CommandSend("history.forward();") ElseIf $Action = "print" Then $Result = CommandSend("print();") EndIf Return $Result EndFunc Func _AFClick($Selector) Local $Result If StringLeft($Selector, 1) = "#" Then ;ID selector $Selector = StringTrimLeft($Selector, 1) $Result = CommandSend('document.getElementById("' & $Selector & '").click();') ElseIf StringLeft($Selector, 1) = "." Then ;Class selector $Result = CommandSend('document.querySelector("' & $Selector & '").click();') EndIf Return $Result EndFunc Func _AFSetValue($Selector, $Value) Local $Result If StringLeft($Selector, 1) = "#" Then ;ID selector $Selector = StringTrimLeft($Selector, 1) $Result = CommandSend('document.getElementById("' & $Selector & '").value = "' & $Value & '";') ElseIf StringLeft($Selector, 1) = "." Then ;Class selector $Result = CommandSend('document.querySelector("' & $Selector & '").value = "' & $Value & '";') EndIf Return $Result EndFunc Func _AFExecute($command) Local $Result = CommandSend($command & ';') Return $Result EndFunc Func _AFScroll($x,$y = 0) Local $Result = CommandSend('window.scrollBy(' & $x & ', ' & $y & ');') Return $Result EndFunc Func WindowDevTools() ;sets firefox debugger to "window" & "console" mode $prefs = _FileListToArrayRec(@AppDataDir & "\Mozilla\Firefox\Profiles", "prefs.js", 1, 1, Default, 2) For $i = 1 to UBound($prefs) -1 FileWriteLine($prefs[$i],'user_pref("devtools.toolbox.host", "window");') FileWriteLine($prefs[$i],'user_pref("devtools.toolbox.selectedTool", "webconsole");') FileWriteLine($prefs[$i],'user_pref("browser.sessionstore.resume_from_crash", false);') Next EndFunc Func CommandSend($command) Local $sOldClip = ClipGet() ;save current clipboard content to Var ClipPut($command) $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "+{Insert}{ENTER}") ClipPut($sOldClip) Return $Result EndFunc