# Problem closing multiple webpages using IE3

## Recommended Posts

Hi,

I'm trying to use IE3 to open three webpages in different instances of IE and then having processed them, close them in the same sequence, i.e. open page 1, do stuff, open page 2, do stuff, open page 3 do stuff then close page 1, then close page 2 then close page 3.

#include <ie.au3>

dim $enteredcount=0 dim$windowdets[3]

$Entered_URL="http://www.cheese.com"$o_IE = _IECreate ()
_IENavigate ($o_IE,$Entered_URL, 1)
_IELoadWait ($o_IE, 1000)$enteredcount+=1
$windowdets[$enteredcount]=$o_IE.locationurl consolewrite("Saving:"&$windowdets[$enteredcount]&@CR)$Entered_URL="http://www.google.com"
$o_IE = _IECreate () _IENavigate ($o_IE, $Entered_URL, 1) _IELoadWait ($o_IE, 1000)
$enteredcount+=1$windowdets[$enteredcount]=$o_IE.locationurl
consolewrite("Saving:"&$windowdets[$enteredcount]&@CR)

$Entered_URL="http://www.chips.com"$o_IE = _IECreate ()
_IENavigate ($o_IE,$Entered_URL, 1)
_IELoadWait ($o_IE, 1000)$enteredcount+=1
$windowdets[$enteredcount]=$o_IE.locationurl consolewrite("Saving:"&$windowdets[$enteredcount]&@CR) msgbox(0,"Close coming up","") _CloseWindows(3) Exit Func _CloseWindows($windowsopen)
local $i For$i=1 to $windowsopen if$windowdets[$i]>"" then consolewrite($windowdets[$i]&@CR)$o_IE=_IEAttach($windowdets[$i],"URL")
if @error>0 then
consolewrite("Couldn't attach to "&$windowdets[$i]&@CR)
$windowdets[$i]=""
ContinueLoop
endif

consolewrite("Attached to "&$windowdets[$i]&@CR)
sleep(2000)
_IEQuit ($o_IE)$windowdets[$i]="" endif Next EndFunc However, it will close the first page, then falls over on the second with this message: >"C:\Program Files\AutoIt3\SciTE\CompileAU3\CompileAU3.exe" /run /beta /ErrorStdOut /in "C:\Program Files\AutoIt3\beta\windowtest.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams >Running AU3Check (1.54.1.1) params: from:C:\Program Files\AutoIt3\beta +>AU3Check ended.rc:0 >Running:(3.1.1.113):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\beta\windowtest.au3" Saving:http://www.cheese.com/ Saving:http://www.google.co.uk/ Saving:http://www.intel.com/design/graphics/mobilegraphics/ http://www.cheese.com/ Attached to http://www.cheese.com/ http://www.google.co.uk/ C:\Program Files\AutoIt3\beta\Include\ie.au3 (275) : ==> The requested action with this object has failed.: If (ObjName($o_window.document) = "DispHTMLDocument") Then

If (^ ERROR

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 13.352

I have identified that removing the IEQuit removes the error (but obviously doesn't close the window, which is sort of the point).

Can anyone advise where I'm going wrong???

##### Share on other sites

I'd like to see a reproducer with valid URL's because I try to avoid untrapped COM errors comming from IE.au3. PM me if you like with the code.

In your case I would expect that you can avoid the issue and simplify your code by using seperate Object variables for each browser window and avoiding the need to ATTACH later.

i.e.

$Entered_URL="some URL"$o_IE1 = _IECreate ($Entered_URL) ;do stuff in$o_IE1

$Entered_URL="some URL"$o_IE2 = _IECreate ($Entered_URL) ;do stuff in$o_IE2

$Entered_URL="some URL"$o_IE3 = _IECreate ($Entered_URL) ;do stuff in$o_IE3

_IEQuit($o_IE1) _IEQuit($o_IE2)

Thanks

Paul

##### Share on other sites

You need to show code and the exact error.

Dale

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

Automate input type=file (Related)

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 on other sites

Hi Dale,

Here's my code. You'll see I changed it a little as I wanted to have an array of internet explorer instances rather than $oe_1,$oe_2 as I'm undecided about how many windows I wanted to have open at once. However, it still bombs out at the $o_IEi[$i].focus line, which I didn't expect as I thought that this was valid (since this is what _IEAction does)....

#include <ie.au3>

dim $i=0 dim$o_IEi[3]

$Entered_URL="http://www.yahoo.com"$o_IEi[0] = _IECreate ()
_IENavigate ($o_IEi[0],$Entered_URL, 1)

$Entered_URL="http://www.google.com"$o_IEi[1] = _IECreate ()
_IENavigate ($o_IEi[1],$Entered_URL, 1)

$Entered_URL="http://www.altavista.com"$o_IEi[2] = _IECreate ()
_IENavigate ($o_IEi[2],$Entered_URL, 1)

msgbox(0,"Close coming up","")
_CloseWindows(2)
Exit

Func _CloseWindows($windowsopen) For$i=0 to $windowsopen consolewrite($i&@CR)
if Isobj($o_IEi[$i]) then
$o_IEi[$i].focus
sleep(2000)
_IEQuit ($o_IEi[$i])
endif
Next
EndFunc

The windows open fine, then the output I get is....

>"C:\Program Files\AutoIt3\SciTE\CompileAU3\CompileAU3.exe" /run /beta /ErrorStdOut /in "C:\Program Files\AutoIt3\beta\windowtest.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams
>Running AU3Check (1.54.1.1)  params:  from:C:\Program Files\AutoIt3\beta
+>AU3Check ended.rc:0
>Running:(3.1.1.113):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Program Files\AutoIt3\beta\windowtest.au3"
0
C:\Program Files\AutoIt3\beta\windowtest.au3 (29) : ==> The requested action with this object has failed.:
$o_IEi[$i].focus
$o_IEi[$i].focus^ ERROR
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 6.758

The IEQuit works fine with $o_IEi[$i] as a parameter, so I'm a bit baffled!

I'm sure I'm making some numpty mistake somewhere. Thanks very much for your help so far anyway.

Cheers

Paul

##### Share on other sites

Well i tried to fudge around and I'm only getting trouble with the .focus... the closing part works fine. Isn't there another way to put it focus (do you need it)

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

##### Share on other sites

Shevilie is right.

So you realize your trouble has nothing to do with IE.au3 right?

If you had used _IEAction($o_IEi[$i], "focus") instead of .focus, IE.au3

would have told you: --> IE.au3 Error from function _IEAction, $_IEStatus_InvalidObjectType because a browser object does not have a .focus method - it is used to give focus to elements on the page (like buttons, form elements etc). To give window focus, you need to use _IEPropertyGet to get the HWND and then use WinActivate to give it focus. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl Automate input type=file (Related) 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 Shevilie is right. So you realize your trouble has nothing to do with IE.au3 right? If you had used _IEAction($o_IEi[$i], "focus") instead of .focus, IE.au3 would have told you: --> IE.au3 Error from function _IEAction,$_IEStatus_InvalidObjectType

because a browser object does not have a .focus method - it is used to give focus to elements on the page (like buttons, form elements etc).

To give window focus, you need to use _IEPropertyGet to get the HWND and then use WinActivate to give it focus.

Dale

Thanks Dale, I'll get my coat.

## Create an account

Register a new account

×

• Wiki

• Back

• Git