Jump to content

_FF_RecordForm (V0.3)


Stilgar
 Share

Recommended Posts

A function to save your input in web-forms and fill them again with FireFox/FF.au3:

1) Fill out the form

2) Let the cursor in this form

3) Start the function

4) Then it returns a script for the FF.au3 to fill out this form again.

; #FUNCTION# ===================================================================
; Name ..........: _FF_RecordForm
; Description ...:
; AutoIt Version : V3.3.0.0
; Requirement(s).: FF.au3 / MozRepl
; Syntax ........: _FF_RecordForm()
; Parameter(s): .:              -
; Return Value ..: Success      - FF.au3 functions to fill the form
;                  Failure      - empty string
; Author(s) .....: Thorsten Willert
; Date ..........: Thu Nov 05 13:43:14 CET 2009
; Version .......: 0.3
; ==============================================================================
Func _FF_RecordForm()
    Local $sScript = ""
    Local $sCmd, $tmp, $iElements, $sType

    _FFCmd("FFau3.tmp=window.content.document.activeElement;")
    For $i = 0 To _FFGetLength("form") -1
        $iElements = _FFFormGetElementsLength($i) - 1
        For $j = 0 To $iElements
            If _FFCmd("FFau3.tmp==window.content.document.forms[" & $i & "].elements[" & $j & "] ? 1 : 0") = 1 Then ExitLoop
        Next
        ExitLoop
    Next

    For $j = 0 To $iElements
        $sType = _FFCmd(".forms[" & $i & "].elements[" & $j & "].type")
        Switch $sType
            Case "textarea","text","password"
                $sCmd = StringFormat(".forms[%i].elements[%i].value", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & "='" & __FFValue2Javascript($tmp) & "'"")" & @CRLF
            Case "radio","checkbox"
                $sCmd = StringFormat(".forms[%i].elements[%i].checked", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & '=' & __FFB2S($tmp) & '")' & @CRLF
            Case "select-one"
                $sCmd = StringFormat(".forms[%i].elements[%i].selectedIndex", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & '=' & $tmp & '")' & @CRLF
        EndSwitch
    Next

    Return $sScript
EndFunc   ;==>_FF_RecordForm
Edited by Stilgar
Link to comment
Share on other sites

Thanx.

Maybe it would be better to use hotkey script (resident) and make these steps:

1) Run FF_Form.au3

2) Fill out the form and keep cursor in form fields

3) Press {Ctrl+g} - to pick up current content for fields

4) Press {ESC} - to exit from FF_Form.au3

FF_Form.au3 is here:

#Include <FF.au3>
Global $Script = ""

HotKeySet("^g", "PickUp_FF")
HotKeySet("{ESC}", "Terminate")
HotKeySet("!m", "Message")  ;Alt-m

while 1
    Sleep(100)
wEnd

;===================
func PickUp_FF()
;Connect to a running FireFox
if _FFConnect() Then
 ; get content
  $Script = _FF_RecordForm()
  MsgBox(4096,"", $Script)
 ; disconnect from FireFox
 if _FFDisConnect() Then
;  MsgBox(64, "", "Disconnected from FireFox!")
 else
  MsgBox(64, "", "Can't connect to FireFox!")
 endIf
endIf
endfunc

;===================
func Terminate()
    Exit 0
endfunc

;===================
func Message()
  MsgBox(4096,"", $Script)
endfunc

; #FUNCTION# ===================================================================
; Name ..........: _FF_RecordForm
; Description ...:
; AutoIt Version : V3.3.0.0
; Requirement(s).: FF.au3 / MozRepl
; Syntax ........: _FF_RecordForm()
; Parameter(s): .:              -
; Return Value ..: Success      - FF.au3 functions to fill the form
;                  Failure      - empty string
; Author(s) .....: Thorsten Willert
; Date ..........: Wed Sep 16 17:52:41 CEST 2009
; Version .......: 0.2
; ==============================================================================
Func _FF_RecordForm()
    Local $sScript = ""
    Local $sCmd, $tmp, $iElements, $sType

    _FFCmd("FFau3.tmp=window.content.document.activeElement;")
    For $i = 0 To _FFGetLength("form") -1
        $iElements = _FFFormGetElementsLength($i) - 1
        For $j = 0 To $iElements
            If _FFCmd("FFau3.tmp==window.content.document.forms[" & $i & "].elements[" & $j & "] ? 1 : 0") = 1 Then ExitLoop
        Next
        ExitLoop
    Next

    For $j = 0 To $iElements
        $sType = _FFCmd(".forms[" & $i & "].elements[" & $j & "].type")
        Switch $sType
            Case "password"
                ContinueCase
            Case "text"
                ContinueCase
            Case "textarea"
                $sCmd = StringFormat(".forms[%i].elements[%i].value", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & "='" & __FFValue2Javascript($tmp) & "'"")" & @CRLF
            Case "checkbox"
                ContinueCase
            Case "radio"
                $sCmd = StringFormat(".forms[%i].elements[%i].checked", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & '=' & __FFB2S($tmp) & '")' & @CRLF
            Case "select-one"
                $sCmd = StringFormat(".forms[%i].elements[%i].selectedIndex", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & '=' & $tmp & '")' & @CRLF
        EndSwitch
    Next

    Return $sScript
EndFunc   ;==>_FF_RecordForm

FF_Form.au3 just shows content of form in message box. Good idea is to make from $Script the file (or script) to launch it in future.

:)

The point of world view

Link to comment
Share on other sites

  • 3 weeks later...

Thanx.

Maybe it would be better to use hotkey script (resident) and make these steps:

1) Run FF_Form.au3

2) Fill out the form and keep cursor in form fields

3) Press {Ctrl+g} - to pick up current content for fields

4) Press {ESC} - to exit from FF_Form.au3

FF_Form.au3 is here:

#Include <FF.au3>
Global $Script = ""

HotKeySet("^g", "PickUp_FF")
HotKeySet("{ESC}", "Terminate")
HotKeySet("!m", "Message")  ;Alt-m

while 1
    Sleep(100)
wEnd

;===================
func PickUp_FF()
;Connect to a running FireFox
if _FFConnect() Then
 ; get content
  $Script = _FF_RecordForm()
  MsgBox(4096,"", $Script)
 ; disconnect from FireFox
 if _FFDisConnect() Then
;  MsgBox(64, "", "Disconnected from FireFox!")
 else
  MsgBox(64, "", "Can't connect to FireFox!")
 endIf
endIf
endfunc

;===================
func Terminate()
    Exit 0
endfunc

;===================
func Message()
  MsgBox(4096,"", $Script)
endfunc

; #FUNCTION# ===================================================================
; Name ..........: _FF_RecordForm
; Description ...:
; AutoIt Version : V3.3.0.0
; Requirement(s).: FF.au3 / MozRepl
; Syntax ........: _FF_RecordForm()
; Parameter(s): .:              -
; Return Value ..: Success      - FF.au3 functions to fill the form
;                  Failure      - empty string
; Author(s) .....: Thorsten Willert
; Date ..........: Wed Sep 16 17:52:41 CEST 2009
; Version .......: 0.2
; ==============================================================================
Func _FF_RecordForm()
    Local $sScript = ""
    Local $sCmd, $tmp, $iElements, $sType

    _FFCmd("FFau3.tmp=window.content.document.activeElement;")
    For $i = 0 To _FFGetLength("form") -1
        $iElements = _FFFormGetElementsLength($i) - 1
        For $j = 0 To $iElements
            If _FFCmd("FFau3.tmp==window.content.document.forms[" & $i & "].elements[" & $j & "] ? 1 : 0") = 1 Then ExitLoop
        Next
        ExitLoop
    Next

    For $j = 0 To $iElements
        $sType = _FFCmd(".forms[" & $i & "].elements[" & $j & "].type")
        Switch $sType
            Case "password"
                ContinueCase
            Case "text"
                ContinueCase
            Case "textarea"
                $sCmd = StringFormat(".forms[%i].elements[%i].value", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & "='" & __FFValue2Javascript($tmp) & "'"")" & @CRLF
            Case "checkbox"
                ContinueCase
            Case "radio"
                $sCmd = StringFormat(".forms[%i].elements[%i].checked", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & '=' & __FFB2S($tmp) & '")' & @CRLF
            Case "select-one"
                $sCmd = StringFormat(".forms[%i].elements[%i].selectedIndex", $i, $j)
                $tmp = _FFCmd($sCmd)
                $sScript &= '_FFCmd("' & $sCmd & '=' & $tmp & '")' & @CRLF
        EndSwitch
    Next

    Return $sScript
EndFunc   ;==>_FF_RecordForm

FF_Form.au3 just shows content of form in message box. Good idea is to make from $Script the file (or script) to launch it in future.

:)

Nice - the function was only to build into scripts like your example, nothing more :-) Edited by Stilgar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...