Jump to content

Automating Embedded Internet Explorer


Recommended Posts

I'm trying to automate a window, which just contains an embedded Internet Explorer, I used the info Tool and it says it's an Ineternet_Explorer_Server

First I start the program

So, I used

$Handle = WinWait("[TITLE:Program Window Name; CLASS:#32770]", "", 30)

$oIE = _IEAttach ($Handle, "Embedded")

Problem is it doesn't work, and that's because it's still loading, I tried _IELoadWait, but that didn't work, the page appears to be Javascript intensive. So I knocked this up... it's probably crude by everyone else's standards:

; Attempt to attach to the embedded IE Object

While 1

$oIE = _IEAttach ($Handle, "Embedded")

If Not @error = $_IEStatus_NoMatch Or @error = $_IEStatus_InvalidObjectType Then ExitLoop

Sleep(100)

WEnd

WinActivate($Handle)

Now comes the tricky bit, I'm waiting for it to load fully and for a Password box to show up... this isn't inside a form tag (another problem I think), to which I want to send a password, followed by enter and wait for the page to load fully again. The password input has a name of "pass".

While 1

$oPass = _IEGetObjByName ($oIE, "pass")

If Not @error = $_IEStatus_NoMatch Then ExitLoop

Sleep(100)

WEnd

This isn't as successful as my first workaround :-/

I can do:

If IsObj($oIE) Then

$sHTML = _IEBodyReadHTML($oIE)

ConsoleWrite($sHTML)

EndIf

Which writes out the content of the HTML

This is trickier than I thought, can someone advise, or point me to some articles, or a tutorial? Thanks.

Link to comment
Share on other sites

Ok, so discovered that it seems to need another "$oIE = _IEAttach ($Handle, "Embedded")" right before I try reading text or html... strange.

Also... if I stick in a "Sleep(1000)" before, then it works, if I don't, I get Access Denied error and the script dies.

As I said, I've try _IELoadWait, but it just sits there until timeout...

I can't see how I can have it wait until the javascript is loaded, or that the "pass" input field has appeared and has focus, or that the javascript password_focus() has run.

Really need some help on this. First the page loads with a simple text line saying "Please wait, loading...", then of course it goes to load and that's when my code dies with:

C:\Program Files (x86)\AutoIt3\Include\IE.au3 (1964) : ==> Variable must be of type "Object".:

Return SetError($_IEStatus_Success, 0, $o_object.document.body.innerText)

Return SetError($_IEStatus_Success, 0, $o_object.document.body^ ERROR

While 1
        Sleep(100)
        ; Attempt to attach to the embedded IE Object
        While 1
            Sleep(100)
            $oIE = _IEAttach($Handle, "Embedded")
            If Not @error = $_IEStatus_NoMatch Then ExitLoop
        WEnd

            $sText = _IEBodyReadText($oIE)
            ConsoleWrite("Is Object" & @CRLF & $sText & @CRLF & @CRLF)

            If Not StringInStr($sText, "Password:") = 0 Then
                ConsoleWrite($sText & " Found")
                ExitLoop
            EndIf

    WEnd
Link to comment
Share on other sites

_IEErrorHandlerRegister() will allow your script to continue past an expected COM error. If that doesn't help, you'll probably need to create a reproduder.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

_IEErrorHandlerRegister() will allow your script to continue past an expected COM error. If that doesn't help, you'll probably need to create a reproduder.

Dale

Thanks Dale, I'll have a look at that.

I've got further since my last post, it seems as though you have to KEEP using _IEAttach before any other commands... doesn't seem to remember it, I guess that's just how it works.

I've got my script working, for the most part now, certainly not as easy and scripting other things, made a few functions, but they need improving, and depending on the speed of the internet connection, the webpage, it can still sometimes through up this error.

I'm doing more testing on it, and _IELoadWait does actually seem to do some waiting, provided you immediately do an _IEAttach right before it... again, didn't realise you had to KEEP Attaching to it... it's the only way some of these functions seem to work, am I right, or is something very odd here?

The first line seems wrong to me, $Handle = WinWait("[TITLE:Program Window Name; CLASS:#32770]", "", 30), has the wrong syntax. Specifically, I think this parameter is wrong, [TITLE:Program Window Name; CLASS:#32770].

Nope, it works, as per the helpfile.
Link to comment
Share on other sites

If the IE you are attaching to is the same instance, _IEAttach will provide the same result each time. Since this is an embedded app however, they could be starting a new IE instance without your knowledge - but it is unlikely. You typically need to use _IEAttach only once.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

If the IE you are attaching to is the same instance, _IEAttach will provide the same result each time. Since this is an embedded app however, they could be starting a new IE instance without your knowledge - but it is unlikely. You typically need to use _IEAttach only once.

Dale

Hmm... although if it was starting a new instance, wouldn't that reload the page?

Well, since reusing that all the time, it's started to work.. next problem was that _IEAction("click") is only click and not onmousedown, onmouseup which typically is what this javascript is waiting for, still thanks to some forum seraching picked up a _IEFullClick function and that works.

Finally it goes through all the motions now in this embedded page, I wrong some functions for reading the Text and HTML and looking for particular sentences to know what stage it was it and when to fire off the next instruction. From a fresh start with no delay, it works great, it's when it's slow get problems, nothing a little tweaking wno't sort out.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...