khumprp Posted October 11, 2011 Share Posted October 11, 2011 (edited) 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 Thanks,Pat BTW - If I do this with Title text instead of the Class, it closes fine. Edited October 11, 2011 by khumprp Link to comment Share on other sites More sharing options...
somdcomputerguy Posted October 11, 2011 Share Posted October 11, 2011 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. Link to comment Share on other sites More sharing options...
khumprp Posted October 11, 2011 Author Share Posted October 11, 2011 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 Link to comment Share on other sites More sharing options...
khumprp Posted October 11, 2011 Author Share Posted October 11, 2011 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? Link to comment Share on other sites More sharing options...
khumprp Posted October 11, 2011 Author Share Posted October 11, 2011 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? Link to comment Share on other sites More sharing options...
JohnOne Posted October 11, 2011 Share Posted October 11, 2011 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. Link to comment Share on other sites More sharing options...
khumprp Posted October 11, 2011 Author Share Posted October 11, 2011 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. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted October 11, 2011 Share Posted October 11, 2011 The returned Class on the window from Window Info tool is MozillaWindowClass. Is the UI one different? Thanks, PatThe 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. Link to comment Share on other sites More sharing options...
khumprp Posted October 11, 2011 Author Share Posted October 11, 2011 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. Link to comment Share on other sites More sharing options...
JohnOne Posted October 11, 2011 Share Posted October 11, 2011 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.** AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
khumprp Posted October 11, 2011 Author Share Posted October 11, 2011 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. Link to comment Share on other sites More sharing options...
Ascend4nt Posted October 12, 2011 Share Posted October 12, 2011 (edited) 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 October 12, 2011 by Ascend4nt mazz3d 1 My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
khumprp Posted October 12, 2011 Author Share Posted October 12, 2011 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? Link to comment Share on other sites More sharing options...
ahha Posted January 22, 2012 Share Posted January 22, 2012 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 pete_wilde and mazz3d 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now