Sign in to follow this  
Followers 0
computerguy9

_ieattach With Dynamic Window Titles

4 posts in this topic

First, many thanks to the great folks who have created AutoIt. I've been using it for a week now and I still find myself giggling like a kid with a new toy every time I get a new program working.

I'm currently working on an AutoIt v3 script that logs into a web page and then navigates through some frames and links. Eventually, I reach the page where I click on the final link (via _IEClickLinkByText) thereby spawning a new window that contains the information I want to capture. For now, all I want to do is write the entire HTML content of that new window to a file. (I'll figure out later how to parse out the bits I need with StringRegExp and StringSplit).

My problem is that the title of the final new window includes a session ID, and hence changes every time I run the AutoIt script. The actual title of the new window looks something like this:

f/g/h/searchnum.php?num=12345&itself=undef&restr=1&SESSID=f87 - Microsoft Internet Explorer

I can correctly determine the thing that comes after "num=", but the value after "SESSID=" is some random number of characters from the front of the session ID.

Is there some function I can use to capture that title "on the fly"? Also how can I subsequently "undo" the _IEAttach and close the window?

So, basically, I'm trying to do something like this:

;--------------------------------------------------------------------------

FOR $final_string IN $final_Array

; Open a file to store the info associated with the current final_string

$file = FileOpen($final_string, 1)

; Spawn final new window that contains desired information

_IEClickLinkByText($fFrame, $final_string)

; Get the title of that final new window

$final_title = _IE_SOME_MAGIC_FUNCTION

; Attach to the final new window

$ObjIE2 = _IEAttach($final_title, "does_this_matter")

_IELoadWait($ObjIE2)

: write the desired information to the file

FileWrite($file, $ObjIE2)

FileClose($file)

; Close the final new window

_IE_MAGICALLY_CLOSE_WINDOW($ObjIE2)

NEXT

;--------------------------------------------------------------------------

So my questions are:

1) What should _IE_SOME_MAGIC_FUNCTION be?

2) Does _IEAttach need the second parameter I have called "does_this_matter"? (Some of the examples in the forum use it and some don't.)

3) Finally, what should _IE_MAGICALLY_CLOSE_WINDOW be so that I can keep looping through a bunch of $final_strings without leaving a million windows open?

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites



I haven't played around with the _IE UDFs, but it seems like your problem with that window could be solved by toying with the WinTitleMatchMode Options... Have you looked into that?

Share this post


Link to post
Share on other sites

I haven't played around with the _IE UDFs, but it seems like your problem with that window could be solved by toying with the WinTitleMatchMode Options... Have you looked into that?

Thanks exodius, your idea worked. It took a bit of fiddling, but this is

what ended up working (in case someone else finds the info useful):

-------------------------------------------------

_IEClickLinkByText($fFrame, $final_string)

opt('WinTitleMatchMode', 2)

Sleep(2000)

$ObjIE2 = _IEAttach("searchnum", "url")

_IELoadWait($ObjIE2)

Sleep(3000)

If not isObj($ObjIE2) Then

$errmsg = StringFormat("NOT AN OBJECT %s", @ERROR)

MsgBox(0, "Error", $errmsg)

EndIf

$htmlbody2 = _IEBodyReadHTML($ObjIE2)

FileWrite($file, $htmlbody2)

WinClose("itself=undef&restr=1&SESSID", "")

-------------------------------------------------

The tricky part was:

$ObjIE2 = _IEAttach("searchnum", "url")

All of the following did NOT work:

$ObjIE2 = _IEAttach("itself=undef&restr=1&SESSID", "Title") ;WRONG

$ObjIE2 = _IEAttach("itself=undef&restr=1&SESSID", "Url") ;WRONG

$ObjIE2 = _IEAttach("SESSID", "Title") ;WRONG

$ObjIE2 = _IEAttach("searchnum", "Title") ;WRONG

It's interesting that with opt('WinTitleMatchMode', 2) the function

WinClose works with the partial title shown, but _IEAttach did NOT

work with that same partial title. It seems like I had to use a part

before any "&", "=", etc. It also seemed like I had to match a URL

rather than a title (which was OK in my case, because the window title

WAS the URL). I did not test the "WRONG" cases above exhaustively. It's

possible one or more of them might work, and I was just doing something

else dumb. The MsgBox(0, "Error", $errmsg) kept showing me that

the value of @ERROR = 1, which means "no match" according to the

comments at the beginning of the _IEAttach function in the file IE.au3.

Eventually, I just tried $ObjIE2 = _IEAttach("searchnum", "url") and

everything worked.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

First, many thanks to the great folks who have created AutoIt. I've been using it for a week now and I still find myself giggling like a kid with a new toy every time I get a new program working.

Welcome to the forums and I'm glad you are having fun -- I think that getting that "giggling like a kid" reaction is what we are all striving for :think:

You'll see from the code of _IEAttach that both the title and url matching modes look for a sub-string anywhere in the title|url so if the url and title are in fact identical then they should match equally as well.

Case $s_mode = "title"
                    If StringInStr($o_window.document.title, $s_string) > 0 Then
                        SetError(0)
                        Return $o_window
                    EndIf
                Case $s_mode = "url"
                    If StringInStr($o_window.LocationURL, $s_string) > 0 Then
                        SetError(0)
                        Return $o_window
                    EndIf

Perhaps there is something odd about the title string... since you have been able to attach to it now, you could examine the title with

MsgBox(0, "Window Title", $objIE2.document.title)
or get the value into a string and examine it:
$sTitle = $objIE2.document.title

It looks like the only spot you are now using the WinTitleMatchMode is in your WinClose statement (IE.au3 doesn't use it as I think you know). Once you have $objIE2 you can use

_IEQuit($objIE2)

You've gotten quite a ways in a week. Keep up the good work.

Dale

Edit: Typo

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

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