PeerMedia Posted May 19, 2011 Posted May 19, 2011 Hello, New to the board, been using AutoIT for a few weeks now but I'm a little stuck on trying to get _IEAttach to work when the window doesn't exist yet. What I'm doing is creating an instructional application and I'd like some interaction between the AutoIT app and IE. When a user starts a browser, they're instructed to do certain actions, I'd like AutoIT to trigger a message when the user visits a specific url (say Google.com). I'd like my app to keep waiting until an IE client matches (could be matched in multiple IE windows too) this url. Using _IEAttach I can successfully attach to the correct IE window if I run the app when the IE window exists. What I'm not sure how to do, is how do I keep looping and waiting in my app until _IEAttach is successful in attaching and then triggering a simple MsgBox()? Thanks!
wakillon Posted May 19, 2011 Posted May 19, 2011 Something like this ? #include <IE.au3> Global $_URL Do $oIE = _IEAttach ( "google" ) If Not @error Then $_URL = _IEPropertyGet ( $oIE, "locationurl" ) ConsoleWrite ( "$_URL : " & $_URL & @Crlf ) EndIf Sleep ( 1000 ) Until $_URL= 'http://www.google.com/' AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
PeerMedia Posted May 19, 2011 Author Posted May 19, 2011 That works, thank you! Do you happen to know how to embed the "waiting" portion within a GUI that's waiting for events? For example: GUICreate("None", 400, 400, 0, 0, $WS_OVERLAPPED + $WS_CAPTION + $WS_THICKFRAME + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 300, 300) GUISetState() ;Show GUI While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd GUIDelete() Exit A majority of the time, my GUI is waiting for events to trigger. Is there a way to incorporate the code you provided into the GUI "waiting" state where its constantly monitoring the url? Thanks again, I really appreciate it!
wakillon Posted May 19, 2011 Posted May 19, 2011 One way...#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <IE.au3> AdlibRegister ( '_CheckWebSite', 1000 ) Global $_URL, $oIE GUICreate("None", 400, 400, 0, 0, $WS_OVERLAPPED + $WS_CAPTION + $WS_THICKFRAME + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) $GUIActiveX = GUICtrlCreateObj($oIE, 0, 0, 300, 300) GUISetState() ;Show GUI While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd GUIDelete() Exit Func _CheckWebSite ( ) $oIE = _IEAttach ( "google" ) If Not @error Then $_URL = _IEPropertyGet ( $oIE, "locationurl" ) If $_URL = 'http://www.google.com/' Then ConsoleWrite ( "$_URL : " & $_URL & @Crlf ) ; do action EndIf EndIf EndFunc ;==> _CheckWebSite ( ) AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
PeerMedia Posted May 19, 2011 Author Posted May 19, 2011 I never knew about an Adlib function, that's exactly what I was looking for. Thanks! This should be a breeze now
wakillon Posted May 19, 2011 Posted May 19, 2011 Glad to help you !For more details see AdlibRegister and AdlibUnRegister functions in the helpfile AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
PeerMedia Posted May 20, 2011 Author Posted May 20, 2011 Hi again, sorry to bother you yet again, do you know a way to cycle through every IE currently open? Under _CheckWebSite, its setup to attach to "google", is there a way to query every $IE object that's currently open (attach to every IE and then the rest of your code will automatically query each $oIE's locationurl)? Thanks again!
wakillon Posted May 20, 2011 Posted May 20, 2011 (edited) Hi again, sorry to bother you yet again, do you know a way to cycle through every IE currently open? Under _CheckWebSite, its setup to attach to "google", is there a way to query every $IE object that's currently open (attach to every IE and then the rest of your code will automatically query each $oIE's locationurl)? Thanks again! Try this #include <IE.au3> ShellExecute ( "iexplore.exe", "http://www.autoitscript.com/forum/topic/122085-how-to-get-from-handle-to-object/page__gopid__847418#entry847418" ) ShellExecute ( "iexplore.exe", "http://www.youtube.com/watch?v=Dwimc4cvUmQ&feature=aso" ) ShellExecute ( "iexplore.exe", "http://www.google.fr/" ) ShellExecute ( "iexplore.exe", "http://www.youtube.com/watch?v=D7K3wFXJFsQ" ) Sleep ( 5000 ) Global $i = 0 While 1 $oIE = _IEAttach ( ":", "URL", $i+1 ) If @error = $_IEStatus_NoMatch Then ExitLoop $_URL = _IEPropertyGet ( $oIE, "locationurl" ) ConsoleWrite ( "$_URL : " & $_URL & @Crlf ) $i += 1 WEnd ConsoleWrite ( "Number of browser instances : " & $i & @Crlf ) Script will detect url of all ie instances with all Tabs ! Edited May 21, 2011 by wakillon AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
PeerMedia Posted May 21, 2011 Author Posted May 21, 2011 Hi, it only worked once (my guess is because the $i loop variable kept going up and up and not matching more instances of IE). But moving $i=0 from the top of the script to the top of the adlib function made it work and keeps itterating. Thanks again, you've been a huge help.
wakillon Posted May 21, 2011 Posted May 21, 2011 Hi, it only worked once (my guess is because the $i loop variable kept going up and up and not matching more instances of IE). But moving $i=0 from the top of the script to the top of the adlib function made it work and keeps itterating. Thanks again, you've been a huge help.I use ":" as title sub-string for search all IE Windows but you can try with an other string if you want filter result...Glad to help you ! AutoIt 3.3.18.0 X86 - SciTE 5.5.7 - WIN 11 24H2 X64 - Other Examples Scripts
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