Jump to content

Automating FireFox Save As Dialog


Pogo
 Share

Recommended Posts

Hi all,

I've been trying to automate the process of the Save As dialog box (example attached) on Firefox, and although i've got the automation part coded, i'm currently stuck at trying to tie it to just Firefox. At the moment it just searches for the dialog box using [CLASS:MozillaDialogClass;], which works but obviously if you have another mozilla based browser open (SeaMonkey etc) it tries to automate that as well.

So has anyone got any ideas on how i can get the automation to react only to Firefox? I tried to use PIDs (it returns a pid fine) and then use ProcessList to get the name, but the ProcessList returns false. I've also looked into using the FF.au3 and _FF_DM.au3, but i can't see a way they'd be useful (maybe i've overlooked the source code in both of them) in doing this.

Code as it stands:

;Loop Every X Milliseconds
While Sleep(2000)
    ;If Save Dialog Pops Up
    If WinExists("[CLASS:MozillaDialogClass;]", "") Then
        $WinTitle = WinGetTitle("[CLASS:MozillaDialogClass;]", "")
        ;Check That it's for Opening a file
        If StringMid($WinTitle, 1, 7) = "Opening" Then
            ;Get Save As Dialog Position
            $winPos = WinGetCaretPos()
            If Not @error Then
                ;Check Save As
                MouseClick("left", $winPos[0]+42, $winPos[1]+164)
                ;Wait 100ms before selecting OK
                Sleep(100)
                ;Click OK
                MouseClick("left", $winPos[0]+297, $winPos[1]+258)
            EndIf
        EndIf
    EndIf
WEnd

Thanks for any help in advance :)

post-37413-12549352978747_thumb.jpg

Link to comment
Share on other sites

Hi all,

I've been trying to automate the process of the Save As dialog box (example attached) on Firefox, and although i've got the automation part coded, i'm currently stuck at trying to tie it to just Firefox. At the moment it just searches for the dialog box using [CLASS:MozillaDialogClass;], which works but obviously if you have another mozilla based browser open (SeaMonkey etc) it tries to automate that as well.

So has anyone got any ideas on how i can get the automation to react only to Firefox? I tried to use PIDs (it returns a pid fine) and then use ProcessList to get the name, but the ProcessList returns false. I've also looked into using the FF.au3 and _FF_DM.au3, but i can't see a way they'd be useful (maybe i've overlooked the source code in both of them) in doing this.

Code as it stands:

;Loop Every X Milliseconds
While Sleep(2000)
    ;If Save Dialog Pops Up
    If WinExists("[CLASS:MozillaDialogClass;]", "") Then
        $WinTitle = WinGetTitle("[CLASS:MozillaDialogClass;]", "")
        ;Check That it's for Opening a file
        If StringMid($WinTitle, 1, 7) = "Opening" Then
            ;Get Save As Dialog Position
            $winPos = WinGetCaretPos()
            If Not @error Then
                ;Check Save As
                MouseClick("left", $winPos[0]+42, $winPos[1]+164)
                ;Wait 100ms before selecting OK
                Sleep(100)
                ;Click OK
                MouseClick("left", $winPos[0]+297, $winPos[1]+258)
            EndIf
        EndIf
    EndIf
WEnd

Thanks for any help in advance :)

Once you know the right PID, it should be easy to run a loop that only looks at windows of that PID. WinList() for a list of mozilla windows, and compare WinGetProcess() to see if it's the right one. This demo list all visible windows of Firefox, and should ignore mozilla windows of other programs:
#include <Array.au3>

HotKeySet("{ESC}", "_Quit")

Global $FF_PID, $avMozList, $sMsg
$FF_PID = ProcessExists("firefox.exe")
If $FF_PID <> -1 Then
    ConsoleWrite("Firefox PID = " & $FF_PID & @LF)
    While ProcessExists($FF_PID)
        ; List all Mozilla windows
        $avMozList = WinList("[REGEXPCLASS:Mozilla.+]", "")

        ; Delete non-Firefox and non-visible Mozilla windows from list
        For $n = $avMozList[0][0] To 1 Step -1
            If (WinGetProcess($avMozList[$n][1], "") = $FF_PID) And _
                    BitAND(WinGetState($avMozList[$n][1]), 0x2) Then
                ContinueLoop
            Else
                _ArrayDelete($avMozList, $n)
            EndIf
        Next
        $avMozList[0][0] = UBound($avMozList) - 1

        ; Display results
        $sMsg = $avMozList[0][0] & " Firefox windows:" & @CRLF
        For $n = 1 To $avMozList[0][0]
            $sMsg &= @TAB & $n & " = " & $avMozList[$n][0] & " (" & $avMozList[$n][1] & ")" & @CRLF
        Next
        ToolTip($sMsg)
        Sleep(250)
    WEnd
Else
    MsgBox(16, "Error", "Firefox is not running")
    Exit
EndIf

Func _Quit()
    Exit
EndFunc   ;==>_Quit

This gets all Mozilla* class windows and displays only those associated with Firefox. You could make it more specific to only dialog windows with the CLASS definition you used before.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...