Sign in to follow this  
Followers 0
Zohar

[Solved] Attach to an IE created by Run(IE+URL)?

18 posts in this topic

#1 ·  Posted (edited)

Hello

I would like to make a small function, that gets a $URL as parameter,

and Runs IE with that URL, and attaches to that opened IE.

If I do it in the regular way of IECreate, IEAttach, then IENavigate, it works.

But If I do it like this:

Run("""C:\Program Files\Internet Explorer\iexplore.exe"" " & $URL)

(meaning that the IE being run is getting the URL instantly)

how will I Attach to it, if $URL can change everytime the function is run?

(IEAttach with $mode="url" will not be good, since sometimes when you give a URL, when IE loads it, it might change a little)

Thank you

Edited by Zohar

Share this post


Link to post
Share on other sites



Hello

I would like to make a small function, that gets a $URL as parameter,

and Runs IE with that URL, and attaches to that opened IE.

If I do it in the regular way of IECreate, IEAttach, then IENavigate, it works.

But If I do it like this:

Run("""C:\Program Files\Internet Explorer\iexplore.exe"" " & $URL)

(meaning that the IE being run is getting the URL instantly)

how will I Attach to it, if $URL can change everytime the function is run?

(IEAttach with $mode="url" will not be good, since sometimes when you give a URL, when IE loads it, it might change a little)

Thank you

A bit difficult to make sense of that.

If I do it in the regular way of IECreate, IEAttach, then IENavigate, it works.

If that works then how did you find the correct url? If you can find the correct url why can't you use it in your RUN example?

If you can't find the correct url then how can we answer your question?

:\


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

"the regular way of IECreate, IEAttach, then IENavigate"

means:

Run("C:\Program Files\Internet Explorer\iexplore.exe");
WinWaitActive("Blank Page")
IE_Attach("about:blank","url")oÝ÷ Ù8^Qⲫ¨µ¦èºÖåjy*ºl¢)í«jÇ«ºyâ§zjmÈ-éÈÖ¯­zØ^­è¬k¡¹^­Â§Ê°j{m¢»§jrjw`÷­å-«¥ªÚë^®X¤zØb±«­¢+ÙIÕ¸ ÅÕ½ÐìÅÕ½ÐìÅÕ½ÐíèÀäÈíAɽɴ¥±ÌÀäÈí%¹ÑɹÐáÁ±½ÉÈÀäÈí¥áÁ±½É¹áÅÕ½ÐìÅÕ½ÐìÅÕ½ÐìµÀìÀÌØíUI0

so the IE window will load with the URL,

that's where I need help :)

Edited by Zohar

Share this post


Link to post
Share on other sites

Does this help?

#640724

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

#5 ·  Posted (edited)

Hello Dale and Thank you very much for your reply

The idea you show there is cool, but it will not enable to open an IE with the URL being loaded instantly.

Using that solution means that the IE first has to be opened empty, and only then get the URL and navigate to it.

I thought of another solution that I am trying to implement, which is this:

#Include <IE.au3>
#include <_ProcessGetHWnd.au3>



Local   $URL    ="google.com"

Local   $PID    =Run("""C:\Program Files\Internet Explorer\iexplore.exe"" " & $URL)
Sleep(2000)
Local   $hWnd   =_ProcessGetHWnd($PID)
ConsoleWrite(WinGetTitle($hWnd) & @CRLF)

Local   $oIE    =_IEAttach($hWnd,"HWND")
_IELoadWait($oIE)
Beep(2000,50)

(_ProcessGetHWnd() was created by Helge: www.autoitscript.com/fileman/users/Helge/udfs/_ProcessGetHWnd.au3 )

The codepiece that I showed above, is working half of the times :)

If you try it on google.com or several other sites, it will attach successfully.

If you try it on microsoft.com or several other sites, it will fail to attach. (and I ask myself why..)

Here is the result that I get in the Output window, when it doesn't work:

CODE

http://microsoft.com/ - Windows Internet Explorer

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

--> IE.au3 V2.4-0 Error from function _IELoadWait, $_IEStatus_InvalidDataType

>Exit code: 0 Time: 3.021

I really want to make this work...

Edited by Zohar

Share this post


Link to post
Share on other sites

The url you pass to the _IECreateNew function referenced in the other note cannot make a difference. The URL is not touched until after the _IEAttach. You also show a warning with _IELoadWait - where is that comming from?

You'd better show your code because this is not matching up.

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

You also show a warning with _IELoadWait - where is that comming from?

It's coming from the line of code that is second from the end..

see? there's a _IELoadWait($oIE) line there,

and after that a Beep(2000,50)

Share this post


Link to post
Share on other sites

Sorry, I misunderstood. I thought you were using the _IECreateNew function I pointed you to. Why will that not work for you?


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

#9 ·  Posted (edited)

Hi :]

_IECreateNew() will not enable to open an IE with the URL being loaded instantly.

It first opens an empty IE(empty = with blank URL), and only then sets the URL and navigate to it.

I want IE to open instantly with the URL.

like when you do

Run("iexplore.exe somewebsite.com").

Edited by Zohar

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

BTW I found something new:

If I change the Sleep(2000) in line 3 to Sleep(4000), then even websites like microsoft.com load successfully.

This leads me to conclude, that maybe _IEAttach() has a problem to attach to an IE that is in the middle of loading a page,

and can only attach when it's not loading?

Might that be true?

If yes how can I fix it to be able to attach in any state?

#Include <IE.au3>
#include <_ProcessGetHWnd.au3>  ; <-- www.autoitscript.com/fileman/users/Helge/udfs/_ProcessGetHWnd.au3 



Local   $URL    ="microsoft.com"

Local   $PID    =Run("""C:\Program Files\Internet Explorer\iexplore.exe"" " & $URL)
Sleep(2000)
Local   $hWnd   =_ProcessGetHWnd($PID)
ConsoleWrite(WinGetTitle($hWnd) & @CRLF)

Local   $oIE    =_IEAttach($hWnd,"HWND")
_IELoadWait($oIE)
Beep(2000,50)
Edited by Zohar

Share this post


Link to post
Share on other sites

Please emplain why _IECreate("www.microsoft.com") doesn't do what you want. Please explain what you are really trying to accomplish so that we don't waste our time with solutions that don't suit your needs.

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

#12 ·  Posted (edited)

hi (:

_IECreate() uses the same process, session, cookies, etc, for all IEs that it opens..

I prefer Complete Seperation between every IE I open.

That's why I am running IE myself, with Run().

Now all I'm trying to get, is to Open an IE, having it get the URL via command line,

and then wanting to Attach to it, so I can automate it.

Since Run() returns me a PID, I am using _ProcessGetHWnd($PID) to get an hWnd from that PID,

and then trying to Attach via that hWnd.

and my only problem now, is the Attach part, as explained..

It seems to Attach well to the IE via the hWnd, If the page has finished loading.

but if IE is in the middle of loading a webpage, it does not attach well, and gives the error I posted here before..

Edited by Zohar

Share this post


Link to post
Share on other sites

so should I assume this problem cannot be fixed? :/

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Why not enter a loop, perhaps with a timeout, trying to grab the object with _IEAttach.

Say, like

$iTimer=TimerInit()
Do
    Sleep(10)
    $oIE   =_IEAttach($hWnd,"HWND")
Until (Not @error Or TimerDiff($iTimer)>5000)

*edit - added sleep to keep it less cpu-intensive

Edited by ascendant

Share this post


Link to post
Share on other sites

_IEAttach uses the Shell.Windows collection to find an existing browser instance. Unfortunately, this collection contains both browsers and file explorer windows. So, _IEAttach loops through the collection and tried to focus just on the browser windows - it differentiates them by checking to see if there is a document object available from the top level automation object ($oIE). If you catch it too early, the document object is not yet instantiated.

I've seen that the new IE8 has an option for creating the browser in a new process, but until then these clumsey work arounds are the best I know of -- at least in the general case of providing a UDF. You may be able to come up with something better that fits your specific scenario, but you'll need to roll up your sleeves and get into the guts of all of this on your own.

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

#16 ·  Posted (edited)

Hello Dale and ascendant!!!

First of all:

ascendant!!!

Thank you very much for the simple yet great idea!

Second:

dale!!!

Thank you very much for your reply,

I understand what you mean.

I will take ascendant's cool solution and use it now,

and also recommend to you, to incorporate his idea in your UDF, so everyone can enjoy this..

(if you think it's needed).

I would also like to thank you for the IE UDF, it's really useful, I am sure I say that for many many people!!

Edited by Zohar

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

WRT IE8, I recommend searching for the keyword "TabProcGrowth"

TabProcGrowth=0 may be of use to anyone that wants a single process of IE8.

PS: Thanks for the cool run / pid to ieattach / hwnd code ...

Edited by beroccaboy

Share this post


Link to post
Share on other sites

#18 ·  Posted

hi beroccaboy

I actulally used the "-nomerge" option to overcome the problems IE8 causes to the code here.

If I understand correctly, "-nomerge" means single process for every new IE8 Window,

and TabProcGrowth=0 means single process for every new Tab?

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