Sign in to follow this  
Followers 0
AlanR

Newbie - Using IE.au3

22 posts in this topic

I'm just beginning to dabble with IE.au3 and I'm having trouble with the IE T2 rev 2.chm file when I click the Open this Script button. I'm sure I must have things located in the wrong sub-folders, or I'm missing some file or other.

But on the same topic, I'm envisaging trying to locate and attach to an open browser window, using _IECreate() like shown in the help file example. Specifically, I'd want to find a URL of the type:

http://www.xyz.com/cgi-bin/w3t/newpost.pl* where * is any trailling text. (Perhaps using a RegExp?)

There may be more than one match, but in such a case I'd want the topmost match.

I'd then want to be able to insert text into a named <textarea>. Please excuse the naivity of the question, but I'm just feeling my way in AutoIt, and would like a kickstart with this so that I can begin learning on a "real" project.

thanks

Alan

Share this post


Link to post
Share on other sites



Im confused. What exactly do you want to use _IECreate for?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Im confused. What exactly do you want to use _IECreate for?

I'm probably confused too. From the help file, I was looking at this example:

Example 3

; Attempt to attach to an existing browser displaying a particular website URL

; Create a new browser and navigate to that site if one does not already exist

#include <IE.au3>

$oIE = _IECreate("www.autoitscript.com", 1)

; Check @extended return value to see if attach was successful

If @extended Then

MsgBox(0,"","Attached to Existing Browser")

Else

MsgBox(0,"","Created New Browser")

EndIf

I was hoping to use something similar to obtain an object reference to the target browser window. Reading more though, I see that _IEAttach() is probably better suited to the aim, as in

$oIE = _IEAttach("AutoIt")

This facilitates the substring search as well.

Alan

Share this post


Link to post
Share on other sites

Something like this should work

#include <IE.au3>

$oIE = _IEAttach("AutoIt")
If Not IsObj($oIE) Then
    $oIE = _IECreate("www.autoitscript.com")
EndIf
Thanks for that snippet, although actually creating a new open window wouldn't be appropriate to the situation. I'm wanting to grab the browser window associated with a mail reply in a forum (similar to the URL in a reply on this forum).

I'm actually having trouble now with _IEAttach detecting even simpler URLs of the form:

http://www.xyz.com/cgi-bin/abc/threads.pl

I wonder if it's the .pl exetension, or perhaps searching for a substring beyond the main domin name?

Alan

Share this post


Link to post
Share on other sites

Thanks for that snippet, although actually creating a new open window wouldn't be appropriate to the situation. I'm wanting to grab the browser window associated with a mail reply in a forum (similar to the URL in a reply on this forum).

I'm actually having trouble now with _IEAttach detecting even simpler URLs of the form:

http://www.xyz.com/cgi-bin/abc/threads.pl

I wonder if it's the .pl exetension, or perhaps searching for a substring beyond the main domin name?

Alan

Give an example of what you are having trouble with.

Share this post


Link to post
Share on other sites

Give an example of what you are having trouble with.

I have a browser window open at this URL:

http://www.wopr.com/cgi-bin/w3t/newpost.pl...mp;sb=5&o=0

I am running the following script:

#include <IE_T2[1].0_4.au3>
$oIE = _IEAttach("wopr")
MsgBox(0, "The URL", _IEPropertyGet($oIE, "locationurl"))

I receive the following errors when I run the script, and the msgbox displays "0":

--> IE.au3 Warning from function _IEAttach, $_IEStatus_NoMatch

--> IE.au3 Error from function _IEPropertyGet, $_IEStatus_InvalidDataType

Alan

Share this post


Link to post
Share on other sites

When I go to that URL the window title is "Make a New Post - Forum (Test Area)".

So try this:

#include <IE_T2[1].0_4.au3>

$oIE = _IEAttach("Make a New Post - Forum (Test Area)")
If @error Then
    MsgBox(48, "Error", "Unable to attach to browser.")
    Exit
EndIf
MsgBox(0, "The URL", _IEPropertyGet($oIE, "locationurl"))

Share this post


Link to post
Share on other sites

@AlanR

Please note that _IEAttach has several different modes... the default is a window title match... perhaps what you wanted was $oIE = _IEAttach("wopr", "url") ?

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

Share this post


Link to post
Share on other sites

@AlanR

Please note that _IEAttach has several different modes... the default is a window title match... perhaps what you wanted was $oIE = _IEAttach("wopr", "url") ?

Dale

:D Thank you (and to Big Daddy). This is exactly what I was trying to do... serves me right for starting something new late at night!

I'm still wondering where abouts I should locate the .CHM and associated files, so that the "Open this Script" buttons will work.

many thanks

Alan

Share this post


Link to post
Share on other sites

:D Thank you (and to Big Daddy). This is exactly what I was trying to do... serves me right for starting something new late at night!

I'm still wondering where abouts I should locate the .CHM and associated files, so that the "Open this Script" buttons will work.

many thanks

Alan

The open script buttons not working is an issue with the way they need to be build for beta releases. You need to use cut and paste.

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

Share this post


Link to post
Share on other sites

The open script buttons not working is an issue with the way they need to be build for beta releases. You need to use cut and paste.

Dale

Thanks Dale.

Alan

Share this post


Link to post
Share on other sites

Hi there,

I tried the same thing using IE.au3, but somehow I cannot get it to work. I only get a "0" as adress. Do I do something wrong with _IEAttach ?

One might say it's inexperience, but I just don't see the mistake.

#include "include\IE.au3"

$win_title = WinGetTitle("")
$oIE = _IEAttach ($win_title)
$current_url = _IEPropertyGet ($oIE, "locationurl")
Msgbox(0, "", $current_url)

Share this post


Link to post
Share on other sites

What is the value of $win_title? Does it match an IE window?

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

Share this post


Link to post
Share on other sites

I forgot to post the code for the active window, sorry.

According to the helpfile WinGetTitle("") should return the active window's title.

Updated Code:

#include "include\IE.au3"
AutoItSetOption( "WinTitleMatchMode", 2)

if WinActive(" - Microsoft Internet Explorer") Then
$win_title = WinGetTitle("")
$oIE = _IEAttach ($win_title)
$current_url = _IEPropertyGet ($oIE, "locationurl")
Msgbox(0, "", $current_url)
EndIf

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

EDIT: The following script does NOT work. please read below.

After a little bit of trying around at the weekend, I found a solution:

_IEAttach does not work using the window title as identification. No idea why, but that's the way it is.

It did work using the Window Handle.

if WinActive(" - Microsoft Internet Explorer") Then
    $win_title = WinGetTitle("")
    $handle = WinGetHandle ($win_title)
    $oIE = _IEAttach ($handle, "HWND")
    if @error Then
        MsgBox (64,"Error", "_IEAttach failed!")
    EndIf
    $url = _IEPropertyGet ($oIE, "locationurl")
    Msgbox(0, "URL", $url)
EndIf
Edited by schlitzy

Share this post


Link to post
Share on other sites

Well, I guess I have been shooting a little quick. I thought it would work, while it is actually not.

I keep getting error messages when using the _IEAttach.

Does anyone have experience with this or knows another solution? I simply want to retrieve the URL from a current window and without having to create a new IE-window.

Thank you very much and please excuse the number of posts. But I am lerning quickly.

Share this post


Link to post
Share on other sites

This should give you some ideas.

#include <IE.au3>

Opt("WinTitleMatchMode", 4)

HotKeySet("{Esc}", "_Exit")

$tempHWND = 0

While 1
    $HWND = WinGetHandle("active")
    If $HWND <> $tempHWND Then
        ControlGetHandle($HWND, "", "Internet Explorer_Server1")
        If Not @error Then
            $oIE = _IEAttach($HWND, "HWND")
            If Not @error Then
                $sURL = _IEPropertyGet($oIE, "locationurl")
                ConsoleWrite($sURL & @CR)
            EndIf
        EndIf       
        $tempHWND = $HWND
    EndIf
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Share this post


Link to post
Share on other sites

Thanks big_daddy,

however, when running the script, I still get :

--> IE.au3 Warning from function _IEAttach, $_IEStatus_NoMatch

this just confuses me more and more...

Share this post


Link to post
Share on other sites

@schlitzy - You may still get that message in the console when first opening a browser window. The operation happens before the IE Window has a chance to fully open.

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