Sign in to follow this  
Followers 0
PeerMedia

Trigger Action for _IEAttach When True

10 posts in this topic

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!

Share this post


Link to post
Share on other sites



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.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

One way...Posted Image

#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.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

I never knew about an Adlib function, that's exactly what I was looking for. Thanks! This should be a breeze now :unsure:

Share this post


Link to post
Share on other sites

Glad to help you !

For more details see AdlibRegister and AdlibUnRegister functions in the helpfile Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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  
Followers 0