FF-Management - FireFox.au3

  • Nur nicht hetzen :D

    Ich werde im laufe der Woche eine überarbeitete Version herausbringen. Mit den Frames muß ich mir noch eine Lösung ausdenken.

    Grüße
    Stilgar

  • Ich hätte hier eine Erweiterung für den Parameter -no-remote, der das Starten mehrerer Profile zulässt:

    Spoiler anzeigen
    [autoit]

    ; ==============================================================================
    ; Function ......: _FFStart
    ; Description ...:
    ; Parameter(s) ..: $sURL = "about:blank" Start URL
    ; $sProfile = "default" UserProfile
    ; $bHide = false
    ; $iNewProcess = 1 0 = Connect to existing process
    ; 1 = Start new process
    ; 2 = Connect to an existing process on failure start a new process
    ; +5 = Use the -no-remote param to allow multiple Profiles
    ; $IP = 127.0.0.1
    ; $iPort = 4242
    ; Requirement ...:
    ; Return values .: Success - Socket
    ; Failure - -1
    ; User CallTip: .: ([$sURL = "about:blank"[, $sProfile = "default"[, $iMode = 1[, $bHide = False[, $IP = "127.0.0.1"[, $iPort = 4242]]]]]])
    ; Author(s) .....: Thorsten Willert
    ; Date ..........: 01. September 2007
    ; Note(s) .......:
    ; ==============================================================================
    Func _FFStart($sURL = "about:blank", $sProfile = "default", $iMode = 1, $bHide = False, $IP = "127.0.0.1", $iPort = 4242)
    Local $noRemote = False
    If Not __FFIsIP($IP) Then
    SetError(__FFError("_FFStart", $_FF_ERROR_InvalidDataType, $IP))
    Return -1
    EndIf
    If Not __FFIsPort($iPort) Then
    SetError(__FFError("_FFStart", $_FF_ERROR_InvalidDataType, $iPort))
    Return -1
    EndIf
    If Not __FFIsURL($sURL) Then
    SetError(__FFError("_FFStart", $_FF_ERROR_InvalidDataType, $sURL))
    Return -1
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $Socket = -1
    If $iMode >=5 Then
    $iMode -= 5
    $noRemote = True
    EndIf
    Switch $iMode
    Case 0
    If ProcessExists($_FF_PROC_NAME) Then $Socket = _FFConnect($IP, $iPort)
    Case 1
    __FFStartProcess($sProfile, $bHide,60000,$noRemote)
    If ProcessExists($_FF_PROC_NAME) Then $Socket = _FFConnect($IP, $iPort)
    Case 2
    $Socket = _FFConnect($IP, $iPort, 3000)
    If $Socket = -1 Then
    __FFStartProcess($sProfile, $bHide,60000,$noRemote)
    If ProcessExists($_FF_PROC_NAME) Then $Socket = _FFConnect($IP, $iPort)
    EndIf
    Case Else
    Return -1
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    If $Socket <> -1 Then
    Sleep(2000)
    _FFOpenURL($Socket, $sURL)
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Return $Socket
    EndFunc ;==>_FFStart

    [/autoit][autoit]

    ; ==============================================================================
    ; Function ......: __FFStartProcess
    ; Description ...:
    ; Parameter(s) ..: $sProfile = "default"
    ; $bHide = False
    ; $iTimeOut = 60000
    ; Requirement ...:
    ; Return values .: Success - 1
    ; Failure - 0
    ; User CallTip: .: ([$sProfile = "default"[, $bHide = false[, $iTimeOut=60000]]])
    ; Author(s) .....: Thorsten Willert
    ; Date ..........: 1. September 2007
    ; Note(s) .......:
    ; ==============================================================================
    Func __FFStartProcess($sProfile = "default", $bHide = False, $iTimeOut = 60000,$noRemote=0)

    [/autoit] [autoit][/autoit] [autoit]

    If $sProfile Then
    $sProfile = ' -P "' & $sProfile & '"'
    Else
    $sProfile = ' -P "default"'
    EndIf
    If $noRemote Then
    $noRemote = " -no-remote"
    Else
    $noRemote = ""
    EndIf
    Local $sHKLM = "HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox"
    Local $sVersion = RegRead($sHKLM, "CurrentVersion")
    Local $sFFExe = RegRead($sHKLM & "\" & $sVersion & "\Main", "PathToExe")

    [/autoit] [autoit][/autoit] [autoit]

    If Not $bHide Then
    Run('"' & $sFFExe & '"' & $noRemote & ' -repl' & $sProfile) ; starting with MozRepl
    Else
    Run('"' & $sFFExe & '"' & $noRemote & ' -repl' & $sProfile, "", @SW_HIDE)
    EndIf
    If @error Then
    SetError(__FFError("__FFStartProcess", $_FF_ERROR_GeneralError, "FireFox.exe not found in: " & $sFFExe))
    Return 0
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Local $iTimeOutTimer = TimerInit()
    While 1
    Sleep(1000)
    If ProcessExists($_FF_PROC_NAME) Then ExitLoop
    If (TimerDiff($iTimeOutTimer) > $iTimeOut) Then
    SetError(__FFError("__FFStartProcess", $_FF_ERROR_Timeout, "FireFox process not exists: " & $_FF_PROC_NAME))
    Return 0
    EndIf
    Wend

    [/autoit] [autoit][/autoit] [autoit]

    If $_FF_COM_TRACE Then ConsoleWrite("__FFStartProcess: " & $sFFExe & '" -repl' & $sProfile & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Return 1
    EndFunc ;==>__FFStartProcess

    [/autoit]
  • Wer nun unbedingt jetzt schon aus Frames zugreifen möchte, kann sich über _FFSetGet z.B.: folgende Sachen basteln:

    QuellText-Abfrage:
    content.frames[0].document.body.innerHTML

    Location:
    content.frames[0].document.location.href

    Titel:
    content.frames[0].document.title

    Links:
    content.frames[0].document.links[0].href

    usw.
    im Prinzip alles wie gehabt, nur daß zwischen dem Objekt "content" und "document" noch der Frame angeben wird.

    Wem das zu viel ist, kann in MozLab auch zu dem entsprechenden Objekt wechseln per:

    [autoit]

    _FFSetGet($Socket,"repl.enter(content.frames[0].document)")

    [/autoit]

    dann beziehen sich alle folgende Aufrufe darauf, also

    [autoit]

    _FFSetGet($Socket,"title")

    [/autoit]


    liefert dann den Titel.

    "Zurück" kommt man wieder per:

    [autoit]

    _FFSetGet($Socket,"repl.home()")

    [/autoit]

    Viel Spaß
    Stilgar

  • Stilgar, YMMD/YMMW/YMMM/YMMY :love::love::love:
    genial ^^
    wäre nie darauf gekommen ^^
    hatte immmer nur "content.document.frames ..."
    :thumbup::thumbup::thumbup::thumbup:8o8o8o8o

  • Es gibt eine neue Testversion:
    http://www.thorsten-willert.de/Themen/AutoIt-…tversion/FF.au3

    Und eine Seite zum Ausprobieren des nachfolgenden Testprogramms:
    http://thorsten-willert.de//Themen/AutoIt-FF.au3/test.html
    (die wird noch ausgebaut und in der Online-Hilfe verwendet)

    Beispiel für die Funktion "_FFFormCheckBox":

    Spoiler anzeigen
    [autoit]

    #region Includes
    #include <FF.au3>
    #endregion Includes

    [/autoit] [autoit][/autoit] [autoit]

    $Socket = _FFStart("http://thorsten-willert.de/Themen/AutoIt-FF.au3/test.html")

    [/autoit] [autoit][/autoit] [autoit]

    _FFFormCheckBox($Socket, "salami", true, -1, "value","Pizza","name")
    sleep(500)
    _FFFormCheckBox($Socket, "zutat", true, 1, "name",1,"index")
    sleep(500)
    _FFFormCheckBox($Socket, 0, true, 3, "index",1,"index")
    sleep(1000)
    _FFFormCheckBox($Socket, "z2", false, -1, "id","Pizza","name")

    [/autoit] [autoit][/autoit] [autoit]

    _FFAction($Socket,"Alert","Ende des Beispiels.")

    [/autoit] [autoit][/autoit] [autoit]

    _FFQuit($Socket)

    [/autoit]


    Die Verzögerungen sind nur drin, damit auch was sieht :)

    Passender Ausschnitt aus dem HTMl-Quelltext:

    Spoiler anzeigen
    PHP
    <form action="" methode="" name="Pizza" id="frm2">
    		<fieldset>
    		<legend>Kreuzen Sie die gew&uuml;nschten Zutaten an:</legend>
    			<input type="checkbox" name="zutat" id="z1" value="salami"> Salami<br>
    			<input type="checkbox" name="zutat" id="z2" value="pilze"> Pilze<br>
    			<input type="checkbox" name="zutat" id="z3" value="sardellen"> Sardellen
    		</fieldset>
    	</form>

    [EDIT] Funktion nochmal überarbeitet; damit sollte man nun jede erdenkliche CheckBox ansprechen können :)

    Grüße Stilgar

    4 Mal editiert, zuletzt von Stilgar (31. Mai 2008 um 18:52)