#include-once #include ; #INDEX# ======================================================================================================================= ; Title .........: Firefox Developer Tools Automation UDF Library for AutoIt3 ; UDF Version : 0.1 ; 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/ ; =============================================================================================================================== Func _AFPrepare() 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 ... ;check if firefox is launched If WinExists("[CLASS:MozillaWindowClass]") Then Opt("WinWaitDelay", 10) ; to quickly hide developer tools window ;check if firefox dev tools is launched If Not(WinExists("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]")) Then ProcessClose("firefox.exe") ProcessWaitClose("firefox.exe", 10) WindowDevTools() ShellExecute("firefox.exe", "-devtools -new-tab about:blank") WinWait("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]","", 10) $Result = WinSetState("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]","", @SW_HIDE) EndIf Else ;firefox not launched WindowDevTools() ShellExecute("firefox.exe", "-devtools -new-tab about:blank") WinWait("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]","", 10) $Result = WinSetState("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]","", @SW_HIDE) EndIf EndIf EndFunc Func _AFLoad($URL) Local $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "window.location.href = '" & $URL & "';{ENTER}") Return $Result EndFunc Func _AFWait($Timeout = 10) Local $Result, $OldTitle $OldTitle = WinGetTitle("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]") For $i = 1 to $Timeout If WinGetTitle("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]") <> $OldTitle Then $Result = 1 ExitLoop Else Sleep(1000) EndIf Next Return $Result EndFunc Func _AFLoadWait($URL, $Timeout = 10) Local $Result ;go to blank page first (to fix same page reload infinite wait) Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "window.location.href = 'about:blank';{ENTER}") WinWait("[CLASS:MozillaWindowClass; TITLE:Developer Tools — about:blank]") Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "window.location.href = '" & $URL & "';{ENTER}") For $i = 1 to $Timeout If WinGetTitle("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]") <> "Developer Tools — about:blank" Then $Result = 1 ExitLoop Else Sleep(1000) EndIf Next Return $Result EndFunc Func _AFAction($Action) Local $Result If $Action = "stop" Then $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "window.stop();{ENTER}") ElseIf $Action = "refresh" Then $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "window.location.href = '';{ENTER}") ElseIf $Action = "quit" Then $Result = ProcessClose("firefox.exe") ElseIf $Action = "back" Then $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "history.back();{ENTER}") ElseIf $Action = "forward" Then $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "history.forward();{ENTER}") ElseIf $Action = "print" Then $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", "print();{ENTER}") EndIf Return $Result EndFunc Func _AFClick($Selector) Local $Result If StringLeft($Selector, 1) = "#" Then ;ID selector $Selector = StringTrimLeft($Selector, 1) $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", 'document.getElementById("' & $Selector & '").click();{ENTER}') ElseIf StringLeft($Selector, 1) = "." Then ;Class selector $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", 'document.querySelector("' & $Selector & '").click();{ENTER}') EndIf Return $Result EndFunc Func _AFSetValue($Selector, $Value) Local $Result If StringLeft($Selector, 1) = "#" Then ;ID selector $Selector = StringTrimLeft($Selector, 1) $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", 'document.getElementById("' & $Selector & '").value = "' & $Value & '";{ENTER}') ElseIf StringLeft($Selector, 1) = "." Then ;Class selector $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", 'document.querySelector("' & $Selector & '").value = "' & $Value & '";{ENTER}') EndIf Return $Result EndFunc Func _AFExecute($command) Local $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", $command & ';{ENTER}') Return $Result EndFunc Func _AFScroll($x,$y) Local $Result = Controlsend("[CLASS:MozillaWindowClass; TITLE:Developer Tools — ]", "", "", 'window.scrollBy(' & $x & ', ' & $y & ');{ENTER}') 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");') Next EndFunc