Jump to content
Sign in to follow this  
khumprp

Firefox and WinClose("CLASS:MozillaWindowClass")

Recommended Posts

khumprp

Hi All -

I have a very simple script that pretty much opens a Firefox browser and then closes it.

I'm using the WinWaitActive and WinClose methods on the Firefox class, which I'm getting from the Window Info tool. It appears that the script does the wait properly at the beginning, but the WinClose method fails. The return code on the WinClose is a 1, so it is seeing the window, but the window never actually closes. Here's the code.

Run("C:\Program Files (x86)\Mozilla Firefox\firefox.exe http://www.cnn.com")

WinWaitActive("[CLASS:MozillaWindowClass]")

Send("^a")

Send("^c")

$i = WinClose("[CLASS:MozillaWindowClass]")

msgbox(0,"t",$i)

Note, I'm not making a screen-wipe script... this is just some basic functionality thrown together for an app we're working on in house :graduated:

Thanks,

Pat

BTW - If I do this with Title text instead of the Class, it closes fine.

Edited by khumprp

Share this post


Link to post
Share on other sites
somdcomputerguy

Try using [CLASS:MozillaUIWindowClass], instead of [CLASS:MozillaWindowClass].


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
khumprp

Hi Bruce -

Thanks for the quick reply. I tried that out, but unfortunately it did not work. Additionally, the WinWaitActive seems to fail with that.

The returned Class on the window from Window Info tool is MozillaWindowClass. Is the UI one different?

Thanks,

Pat

Share this post


Link to post
Share on other sites
khumprp

Here's a discovery -

I put a sleep in between the browser opening and closing. If I lose focus on the browser window, it closes just fine.

Thoughts?

Share this post


Link to post
Share on other sites
khumprp

I added this piece of code in. As long as the window exists, try and close it. The MsgBox always returns 1, saying that the window successfully closed, even though it does not.

While WinExists("[CLASS:MozillaWindowClass]")

$i = WinClose("[CLASS:MozillaWindowClass")

msgbox(0,"Exists", $i)

WEnd

Anyone else have this issue?

Share this post


Link to post
Share on other sites
JohnOne

It does not work for me, not even waiting, and don't forget there is a timeout in Winwaitactive which could cause the illusion of working (if there is a default, I'm not sure)

Run("C:\Program Files\Mozilla Firefox\firefox.exe http://www.cnn.com")
WinWaitActive("[CLASS:MozillaUIWindowClass]")
MsgBox(0,0,0)
Send("^a")
Send("^c")
$i = WinClose("[CLASS:MozillaWindowClass]")
msgbox(0,"t",$i)

This however works

Opt("WinTitleMatchMode",2)
Run("C:\Program Files\Mozilla Firefox\firefox.exe http://www.cnn.com")
WinWaitActive("Mozilla Firefox")
MsgBox(0,0,0)
Send("^a")
Send("^c")
$i = WinClose("Mozilla Firefox")
msgbox(0,"t",$i)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
khumprp

Yah, it's weird that it will work on the Title text, but not on the Class... And WinClose even replies back that it has successfully closed it!

On the other hand, the main reason I wasn't doing WinClose with Title was because I was concerned if the Title text would change... I forgot that by default it's set to search in the string, so closing on the "Mozilla Firefox" should be fine.

But I still want to know why the class wont work.

Share this post


Link to post
Share on other sites
somdcomputerguy

The returned Class on the window from Window Info tool is MozillaWindowClass. Is the UI one different? Thanks, Pat

The AutoIt Window Info tool returned [CLASS:MozillaUIWindowClass] for me, so that was just a suggestion I made. The FF version I have is 3.6.something, maybe you're running a different version, and the classname is different.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
khumprp

The AutoIt Window Info tool returned [CLASS:MozillaUIWindowClass] for me, so that was just a suggestion I made. The FF version I have is 3.6.something, maybe you're running a different version, and the classname is different.

Yah, I'm running 6.0.2 Firefox per the About screen. I didn't even realize that Firefox version were that high yet.

Share this post


Link to post
Share on other sites
khumprp

Could be something to do with firefox not being standard windows drawings anymore.

I know you cartainly cannot interact with its controls in versions higher than 3.**

Would explain a variety of things I'm seeing, like sometimes it will close and other times it wont.

Hmm... Wonder if I should just switch to Process Kill? Doesn't seem very clean though.

Share this post


Link to post
Share on other sites
Ascend4nt

There's a number of windows that show up for that class when I have Firefox open. You need to find the right one of course. You *could* use a title search to find '- Mozilla Firefox' in the name, but if you have a document open with that name then you'd be screwed (unless you checked the process too).

Here's one way to go through the window list and find the right Firefox window to close (it looks for a window without the WS_POPUP flag.):

#include <WinAPI.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
Local $hFireFoxWin=0,$aWinList=WinList("[REGEXPCLASS:Mozilla(UI)?WindowClass]")
For $i=1 To $aWinList[0][0]
    If BitAND(_WinAPI_GetWindowLong($aWinList[$i][1],$GWL_STYLE),$WS_POPUP)=0 Then
        $hFireFoxWin=$aWinList[$i][1]
        ExitLoop
    EndIf
Next
If $hFireFoxWin Then WinClose($hFireFoxWin)

*edit: Meh, easiest way:

$hFirefoxWin=WinGetHandle("[REGEXPTITLE: - Mozilla Firefox$;REGEXPCLASS:Mozilla(UI)?WindowClass]")
WinClose($hFirefoxWin)
Edited by Ascend4nt
  • Like 1

Share this post


Link to post
Share on other sites
khumprp

Thanks, I'll try that out.

I'm just trying to find a good "standard" for closing windows. I like the Class key, but as shown with Firefox, it doesn't always work.

Any other recomendations for a standard when closing windows?

Share this post


Link to post
Share on other sites
ahha

Khumprp,

I had similar issues as you, after trying titles and classes, I found the simplest way was to simply kill the process.

ProcessClose("firefox.exe")

This sometimes generates a restore tab when FF is started up again.

If you want to start FF without a restore tab then in FF

1) type about:config in website bar and click ok

2) in Filter type in crash

3) double click browser.sessionstore.resume_from_crash till it says false under value

  • Like 1

Share this post


Link to post
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
Sign in to follow this  

×