Jump to content

Internet Explorer Automation UDF library


DaleHohm
 Share

Recommended Posts

Great library, very useful.

While spending hours with the HTML DOM and the AutoIt COM interface, I had to change your loadwait function for my needs.

Here is my version.

;===============================================================================
;
; Function Name:    _IELoadWait()
; Description:      Wait for a browser page load to complete before returning
; Parameter(s):     $o_object   - InternetExplorer.Application object
;                   $i_delay    - wait this many milliseconds before checking status
; Requirement(s):   AutoIt3 Beta with COM support (post 3.1.1)
; Return Value(s):  On Success  - Returns an object variable pointing to
;                  On Failure   - 0  and sets @ERROR = 1
; Author(s):        Dale Hohm
;
; Note(s):        02/05/2006 (SlimShady): - (Change) Put Sleep($i_delay) in the loop
;                                          - (Change) While loop -> Do loop
;                                          - (Addition) Timeout check (seconds)
;===============================================================================
;
Func _IELoadWait($o_object, $i_delay = 100, $i_timeout = 10)
    Local $iStartTime = TimerInit()
    If IsObj($o_object) Then
        $s_oname = ObjName($o_object)
        Do
            Sleep($i_delay)
            If (Int(TimerDiff($iStartTime) / 1000) >= $i_timeout) Then
               SetError(1)
               Return 0
            EndIf
        Until ($o_object.document.readyState == "complete") OR _
              ($o_object.document.readyState == 4)
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc  ;==>_IELoadWait

(stupid tags)

Edited by SlimShady
Link to comment
Share on other sites

@SlimShady -- glad you find it useful.

The timeout for _IELoadWait() is one of a couple of things that are logical deficiencies in the library. Thanks for sharing your code -- it's actually somethig I've had in my next code baselevel. Sorry we're both inventing the wheel -- something very close to this will be in the next release.

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

Hi Dale,

Saying IE.au3 is a great script is really an underestimation - but it seems my understanding is limited, since I can't figure out how to get the form elements within a frame?

For example the following code is giving me an error (on the second line)

$o_frame = _IEFrameGetObjByIndex($oIE, 0)
$o_form = _IEFormGetObjByName($o_frame, "sendForm")
$o_text = _IEFormElementGetObjByName($o_form, "Msg")

Any suggestions?

Link to comment
Share on other sites

Hi Dale,

Saying IE.au3 is a great script is really an underestimation - but it seems my understanding is limited, since I can't figure out how to get the form elements within a frame?

For example the following code is giving me an error (on the second line)

$o_frame = _IEFrameGetObjByIndex($oIE, 0)
$o_form = _IEFormGetObjByName($o_frame, "sendForm")
$o_text = _IEFormElementGetObjByName($o_form, "Msg")

Any suggestions?

One likely cause is that the first line is not returning you a valid object/frame reference. Check IsObj($o_frame) or check @error. You also might not be getting the correct frame reference ig there is more than one. Take a close look at your top-level page HTML source.

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

One likely cause is that the first line is not returning you a valid object/frame reference. Check IsObj($o_frame) or check @error. You also might not be getting the correct frame reference ig there is more than one. Take a close look at your top-level page HTML source.

Dale

Thanks for the quick reply. It is quite strange since none fail IsObj or @error. The problem seems to be occurring within the IE.au3 script.

I have a feeling _IEFormGetObjByName() function does not accept an object of type frame? Is this correct?

Link to comment
Share on other sites

Thanks for the quick reply. It is quite strange since none fail IsObj or @error. The problem seems to be occurring within the IE.au3 script.

I have a feeling _IEFormGetObjByName() function does not accept an object of type frame? Is this correct?

So long as the object has a .document property, which a frame does, it should work.

I've recently discovered an interesting class of DOM discovery tools called "Favlets" or "Bookmarklets" -- here is a link to one called "Mouseover DOM Inspector". Go to this page and bookmark the link in the middle of the page as it instructs you to do... then if you open the bookmark while on a page, it opens a popup window that shows you the DOM structure as you mouse over elements... very cool. Press Esc to get out of it. This may help you with your investigation.

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

So long as the object has a .document property, which a frame does, it should work.

I've recently discovered an interesting class of DOM discovery tools called "Favlets" or "Bookmarklets" -- here is a link to one called "Mouseover DOM Inspector". Go to this page and bookmark the link in the middle of the page as it instructs you to do... then if you open the bookmark while on a page, it opens a popup window that shows you the DOM structure as you mouse over elements... very cool. Press Esc to get out of it. This may help you with your investigation.

Dale

Thanks. I have looked through the DOM Inspector and it shows that the frame i'm trying to access is an iframe with the following (removed url)

attributes:

* width : 525

* scrolling : auto

* height : 1000

* frameborder : 0

* class : iframenoborder

* name : grouptext

* style : float: left; width: 371px; z-index: 1;

parent structure

* html

* body class="personal"

* div id="frame"

* div id="container"

* div id="middle"

* div id="rightcol"

* div id="contentframe"

* div id="content"

So when I try to get a reference to the framw through the following

$o_frame = _IEFrameGetObjByName($oIE, "grouptext")

If Not IsObj($o_frame) Then
    MsgBox(0, "Error", "No Frame ref")
Else
    Msgbox(0,"Error","Success")
EndIf

works great - no errors (I also check the @error) but when I call the Form function it fails

$o_form = _IEFormGetObjByName($o_frame, "sendForm")

It also throws an error on

$o_frame.document
(I tried this out of curiosity)

Does it make any difference since it is an iframe (rather than frame) and within all those div?

(Sorry if this is a naive question - my background is C++ and I know little about web technologies)

Link to comment
Share on other sites

Preston, Dale,

Did you try to access data in frames from different domains?

This is not possible, because of security restrictions :-)

Dave

Thanks. I have looked through the DOM Inspector and it shows that the frame i'm trying to access is an iframe with the following (removed url)

attributes:

* width : 525

* scrolling : auto

* height : 1000

* frameborder : 0

* class : iframenoborder

* name : grouptext

* style : float: left; width: 371px; z-index: 1;

parent structure

* html

* body class="personal"

* div id="frame"

* div id="container"

* div id="middle"

* div id="rightcol"

* div id="contentframe"

* div id="content"

So when I try to get a reference to the framw through the following

$o_frame = _IEFrameGetObjByName($oIE, "grouptext")

If Not IsObj($o_frame) Then
    MsgBox(0, "Error", "No Frame ref")
Else
    Msgbox(0,"Error","Success")
EndIf

works great - no errors (I also check the @error) but when I call the Form function it fails

$o_form = _IEFormGetObjByName($o_frame, "sendForm")

It also throws an error on

$o_frame.document
(I tried this out of curiosity)

Does it make any difference since it is an iframe (rather than frame) and within all those div?

(Sorry if this is a naive question - my background is C++ and I know little about web technologies)

Link to comment
Share on other sites

works great - no errors (I also check the @error) but when I call the Form function it fails

$o_form = _IEFormGetObjByName($o_frame, "sendForm")
Interesting. Actually, now that I look at the object model more closely, I think this may be the key to a long nagging problem. iFrames do NOT have a document property, but instead have a contentWindow property that in turn has a document property.

Please try the following and see if your error disappears:

$o_form = _IEFormGetObjByName($o_frame.contentWindow, "sendForm")

Dale

p.s. I don't think this problem has anything to do with cross-domain frame issues

Edit: fixed typos

Edited by DaleHohm

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

Dave,

The frame is being accessed from the same domain (i.e. the main page is say at http://www.microsoft.com and the frame source is at http://data.microsoft.com). From reading around I figured this shouldn't pose a security problem. I also checked to make sure that one of them is not HTTP and other HTTPS - but this wasn't the case - both the webpage and the frame are sent over HTTP.

Interesting. Actually, now that I look at the object model more closely, I think this may be the key to a long nagging problem. iFrames do NOT have a document property, but instead have a contentWindow property that in turn has a document property.

Please try the following and see if your error disappears:

$o_form = _IEFormGetObjByName($o_frame.contentWindow, "sendForm")

Dale

p.s. I don't think this problem has anything to do with cross-domain frame issues

Edit: fixed typos

Dale,

This problem is just tormenting. I have tried your suggestion and unfortunately the same problem happens :lmao: I'm wondering if the msdn is the best place to find the properties of the objects? I had a look at the site and I can see the contentwindow. But when I try to read this property e.g.

$o_frame.contentWindow

It fails misreably - eventhough it passed the IsObj() check. How can this be - it just doesn't make any sense!

I'm wondering if anyone has managed to read a form elements within a frame?

edit: url edit

Edited by Preston Ladder
Link to comment
Share on other sites

Preston, Dale,

This is because of the cross-domain frames security issue.

In this context data.microsoft.com and www.microsoft.com are not from the same "domain" :-)

Cheers, Dave

Dave,

The frame is being accessed from the same domain (i.e. the main page is say at http://www.microsoft.com and the frame source is at http://data.microsoft.com). From reading around I figured this shouldn't pose a security problem. I also checked to make sure that one of them is not HTTP and other HTTPS - but this wasn't the case - both the webpage and the frame are sent over HTTP.

Dale,

This problem is just tormenting. I have tried your suggestion and unfortunately the same problem happens :lmao: I'm wondering if the msdn is the best place to find the properties of the objects? I had a look at the site and I can see the contentwindow. But when I try to read this property e.g.

$o_frame.contentWindow

It fails misreably - eventhough it passed the IsObj() check. How can this be - it just doesn't make any sense!

I'm wondering if anyone has managed to read a form elements within a frame?

edit: url edit

Link to comment
Share on other sites

Yes, the input type=file element has lots of scripting restrictions due to security concerns. You need to use a hybrid of SEND() commands along with DOM commands to simulate interactive user input -- fortunately, AutoIt makes this possible.

I forgot about the DOM suspending execution while the file selection box is up -- there is an example working around this using similar methods in the example post (reply 3 of this thread). You should be able to accomplish your goal without having two scripts running though (unless I don't understand your situation).

Dale

Hi Dale,

Thank you for all your help and my apologies for this late reply.

I have managed to solve the problems in accessing the <input type=file> :o

The solution was to use the .focus() method to set the focus to the form element just before

the <input type=file> and use the Send() command to simulate TAB keystrokes to arrive on the browse button and then simulate a SPACE keystroke. This opens the Browse window, which can easily be controlled with 'normal' AutoIT.

When you use TABs to reach a certain form element you should really pay attention to Javascript code that moves the focus to another element as soon as an element get's the focus (onfocus event). It is best to avoid having to pass such a form element.

I hope this is useful information.

Thanks again for your help!

Kind regards,

Jasper de Fockert

Link to comment
Share on other sites

Preston, Dale,

This is because of the cross-domain frames security issue.

In this context data.microsoft.com and www.microsoft.com are not from the same "domain" :-)

Cheers, Dave

I've asked Preston Ladder for reproducer code for this in a PM... haven't heard back. If anyone else can reproduce the trouble I'd like to have a look.

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

Am i wrong if i think its possible to make with the help of this topic a compleet script wich will automatically update pc's with Windows Update? or does this script already excist?

It may get complicated with frames, javascript and activex controls, but a combination of IE.au3 and perhaps add iddition of some other DOM functions not covered in IE.au3 you should be able to accomplish this.

Someone else was asking questions about this just recently, but I don't recall the thread.

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

It may get complicated with frames, javascript and activex controls, but a combination of IE.au3 and perhaps add iddition of some other DOM functions not covered in IE.au3 you should be able to accomplish this.

Someone else was asking questions about this just recently, but I don't recall the thread.

Dale

Then too bad, i am big noob at this.

I will try and maybe i am lucky, but if i put the "IE.au3" file in the INCLUDE folder and test a example script:

#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")

$oFrom = _IEFormGetObjByName($oIE, "sForm")
$oRelevant = _IEFormElementGetObjByName($oFrom, "sortby", 0)
$oRecent = _IEFormElementGetObjByName($oFrom, "sortby", 1)

For $i = 1 to 5
    $oRelevant.checked = True
    Sleep(1000)
    $oRecent.checked = True
    Sleep(1000)
Next

i get this error:

D:\AutoIt3\Include\IE.au3(275,39) : ERROR: ObjName(): undefined function.

If (ObjName($o_window.document)

I have AutoIT3 latest version installed, latest version of scite and the beta is installed wich is in the first post.

Am i doing something wrong?

Link to comment
Share on other sites

Then too bad, i am big noob at this.

I will try and maybe i am lucky, but if i put the "IE.au3" file in the INCLUDE folder and test a example script:

#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "http://www.autoitscript.com/forum/index.php?act=Search&f=")

$oFrom = _IEFormGetObjByName($oIE, "sForm")
$oRelevant = _IEFormElementGetObjByName($oFrom, "sortby", 0)
$oRecent = _IEFormElementGetObjByName($oFrom, "sortby", 1)

For $i = 1 to 5
    $oRelevant.checked = True
    Sleep(1000)
    $oRecent.checked = True
    Sleep(1000)
Next

i get this error:

D:\AutoIt3\Include\IE.au3(275,39) : ERROR: ObjName(): undefined function.

If (ObjName($o_window.document)

I have AutoIT3 latest version installed, latest version of scite and the beta is installed wich is in the first post.

Am i doing something wrong?

AutoIt also spits out the version number it is using to run your code. For future reference, please ALWAYS include that when you ask for help.

From the error message you report however I can tell that you are not running the AutoIt beta (or you could have a beta older than build 63) -- which is required for the COM support that IE.au3 uses. The beta pointer is at the bottom of the AutoIt downloads page. If you have it installed and are using SciTe, make certain that you use Alt-F5 instead of just F5 to run your script so that you get the beta when you run.

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

AutoIt also spits out the version number it is using to run your code. For future reference, please ALWAYS include that when you ask for help.

From the error message you report however I can tell that you are not running the AutoIt beta (or you could have a beta older than build 63) -- which is required for the COM support that IE.au3 uses. The beta pointer is at the bottom of the AutoIt downloads page. If you have it installed and are using SciTe, make certain that you use Alt-F5 instead of just F5 to run your script so that you get the beta when you run.

Dale

Ah i see, if i press Alt+F5 it does nothing, but if i run it trough tools etc. it does. Weird, i think i will remove and reinstall everything again to make sure thats not the problem.

-edit-

How do you guys know what variable you have to use by example clicking on the forum link?

Do you look at the code and search what id it has? or do you just use the name wich you see on screen(not the code part) or is there something like Window Info for this kind of stuff?

Edited by Iznogoud
Link to comment
Share on other sites

I've asked Preston Ladder for reproducer code for this in a PM... haven't heard back. If anyone else can reproduce the trouble I'd like to have a look.

Dale

Dale,

Sorry for a late reply - I managed to read your PM just now.

The website I'm automating is on an intranet - however a simple web page with a set of frames pointing out to different third-level domains should reproduce this problem. As for my solution - instead of retrieving elements of the frame (form, textarea etc), I'm using the current instance of IE to actually 'navigate' to the frame source and then retrieving pointers to the objects (not a great solution but it seems to work).

I'd like to thank you Dale for your timely efforts and suggestions and also Dave for the security suggestion and sorry again for the delayed response.

(if someone does reproduce this problem and gets a different result than mine - it would be nice to put it in this thread)

All the best for now,

Preston.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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