HuaAi Posted July 18, 2015 Share Posted July 18, 2015 I basically just want to run IE, go to google, and activate the IE, but couldn't get it working with the script below. The ToolTip() shows that "IE is open!" and we got the handle of the IE window, but the script was never able to execute the last ToolTip() to show the window is activated.Is there anything I did obviously wrong? I can't find it. Any suggestions? Appreciated! run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.google.com","") ToolTip("Launching IE...", 0, 0) sleep(5000) AutoItSetOption("WinTitleMatchMode", 1) Local $titleIeWindow = "Google " If WinExists($titleIeWindow) Then ToolTip("IE launched successfully.", 0, 0) Else ToolTip("Can't find IE, leave it for WinWaitActive() to wait") EndIf sleep(1000) Global $hdlIeWindow = WinWait($titleIeWindow) ToolTip("IE is open!" & " hWnd = " & $hdlIeWindow, 0, 0) WinActivate($hdlIeWindow) sleep(1000) WinWaitActive($hdlIeWindow, 5) ToolTip("IE is activated!", 0, 0) Link to comment Share on other sites More sharing options...
HuaAi Posted July 18, 2015 Author Share Posted July 18, 2015 BTW, ToolTip() did report "IE launched successfully." so WinExists() seems to be able to detect the window. Link to comment Share on other sites More sharing options...
HuaAi Posted July 18, 2015 Author Share Posted July 18, 2015 Added an extra check after winActivate() and reran it again, ToolTip() reported "WinExists() can detect IE window through $hdlIeWindow too." It confirms that somehow the script gets stuck at WinWaitActive($hdlIeWindow, 5). I am on Win 7 Home Premium, SP1, 64-bit. IE 11. the latest AutoIt version, just downloaded. run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.google.com","") ToolTip("Launching IE...", 0, 0) sleep(3000) AutoItSetOption("WinTitleMatchMode", 1) Local $titleIeWindow = "Google " If WinExists($titleIeWindow) Then ToolTip("IE launched successfully.", 0, 0) Else ToolTip("Can't find IE, leave it for WinWaitActive() to wait") EndIf sleep(1000) Global $hdlIeWindow = WinWait($titleIeWindow) ToolTip("IE is open!" & " hWnd = " & $hdlIeWindow, 0, 0) WinActivate($hdlIeWindow) If WinExists($hdlIeWindow) Then ToolTip("WinExists() can detect IE window through $hdlIeWindow too.", 0, 0) Else ToolTip("Can't find IE, leave it for WinWaitActive() to wait") EndIf sleep(1000) WinWaitActive($hdlIeWindow, 5) ToolTip("IE is activated!", 0, 0) Link to comment Share on other sites More sharing options...
HuaAi Posted July 18, 2015 Author Share Posted July 18, 2015 Could anyone run this simple script on your setup and see if you got the same problem?The ToolTip box is at the top left corner in case you couldn't find it. Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2015 Share Posted July 18, 2015 WinWaitActive($hdlIeWindow, "", 5) HuaAi 1 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...
jguinch Posted July 18, 2015 Share Posted July 18, 2015 $oIE = _IECreate("http://www.google.com") $hIE = _IEPropertyGet($oIE, "hwnd") WinActivate($hIE) HuaAi 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
HuaAi Posted July 18, 2015 Author Share Posted July 18, 2015 WinWaitActive($hdlIeWindow, "", 5)Yeah that fixed the problem! Thanks! Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2015 Share Posted July 18, 2015 Ace.But if you're going beyond just learning or something then the above example would be better. 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...
HuaAi Posted July 18, 2015 Author Share Posted July 18, 2015 $oIE = _IECreate("http://www.google.com") $hIE = _IEPropertyGet($oIE, "hwnd") WinActivate($hIE) Nice! Didn't even know IE.au3 exists. Do we have a library for Chrome too? Link to comment Share on other sites More sharing options...
HuaAi Posted July 18, 2015 Author Share Posted July 18, 2015 After JohnOne pointed out the problem with how I use WinWaitActive(), I fixed my script (test1.au3 in the attachment) and tried to move the window to show I indeed can control the window through its handle. Then I found the script sometimes works and sometimes doesn't. So I added a WinActive() check in the code as below and found sometimes "IE is not activated!" for some reason.If I use jguinch's method to launch and activate IE window, as in the attached test2.au3, then it works every single time!Any idea why test1.au3 is flaky? run( "C:\Program Files\Internet Explorer\IEXPLORE.EXE -new http://www.google.com","") ToolTip("Launching IE...", 0, 0) AutoItSetOption("WinTitleMatchMode", 1) Local $titleIeWindow = "Google " Global $hdlIeWindow = WinWait($titleIeWindow) ToolTip("IE is open!" & " hWnd = " & $hdlIeWindow, 0, 0) sleep(1000) WinActivate($hdlIeWindow) Sleep(2000) If WinActive($hdlIeWindow) Then ToolTip("IE is activated!", 0, 0) Else ToolTip("IE is not activated!", 0, 0) Sleep(2000) WinActivate($hdlIeWindow) Exit EndIf sleep(1000) test2.au3 test1.au3 Link to comment Share on other sites More sharing options...
JohnOne Posted July 18, 2015 Share Posted July 18, 2015 Probably some other application is stealing focus. 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...
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