Sign in to follow this  
Followers 0
cechols

Utilizing an existing IE browser window...

8 posts in this topic

First, let me apologize for being yet another AutoIt fledgling. I'm not a developer by trade, but I've been tasked by my company to create automation tools for our software. I'm a quick study, but my deadlines are closing and I need help.

Here's what I'm trying to accomplish:

1) I've developed a GUI that contains checkboxes for running 25 automation scripts. From this interface, users can check to run any or all of the available automation scripts. No problems here.

2) The automation takes place entirely inside of Internet Explorer on our company site. Because of this, the scripts have to call an IE browser window first. Doing that in itself is no problem ($oIE).

3) Since the script launcher GUI is checkbox-based, any one of the scripts could be the first script a user runs. As such, I have to put a function for opening an IE window at the beginning of each and every script.

And here is where the problem comes in. Since there are 25 scripts in my launcher, I don't want 25 instances of IE to be opened. What I do want is for each successive script to check to see if IE is already open. If it is already existing, then I want it to use the existing instance of IE for navigating.

I'll paste in the code I've been using (knowing full well that it isn't correct) for reference. As it is, the script works - it just always opens a second instance of IE, which I don't want it to do.

$objExcel = ObjCreate("excel.application")
With $objExcel
    .Visible = 0
    .WorkBooks.Open(@ScriptDir & '\Scripts\Excel Sheet 1.xls', Default, False)
    .ActiveWorkbook.Sheets(1).Select ()
EndWith

$myex = ObjGet("", "excel.application");Pull data from excel spreadsheet

If Not IsObj($myex) Then
    MsgBox(0, "Error", "Please open Excel and activate the spreadsheet you want to import")
    Exit
EndIf

$mywb = $myex.activeworkbook
$myws = $mywb.activesheet
$x = 2
$testsite = $myws.range("a" & $x).formula
$username = $myws.range("b" & $x).formula
$password = $myws.range("c" & $x).formula

$oIE = _IECreate($testsite)
    WinSetState("", "", @SW_MAXIMIZE)
    
If ProcessExists("iexplore.exe") Then
    _IELinkClickByText($oIE, "Planning")
    _IEImgClick($oIE, "Admin.jpg")
Else
    ;Create IE Window + Login
    $oUser = _IEGetObjByName($oIE, "Login1_UserName")
    _IEFormElementSetValue($oUser, $username)
    $oPass = _IEGetObjByName($oIE, "Login1_Password")
    _IEFormElementSetValue($oPass, $password)
    $oLogIn = _IEGetObjByName($oIE, "Login1_LoginButton")
    _IEAction($oLogIn, "click")
    _IELoadWait($oIE)

    ;Navigate to Organization Page
    _IELinkClickByText($oIE, "Planning")
    _IEImgClick($oIE, "Admin.jpg")
EndIf

All I need it to do is this:

1) Check for an open IE window

2) If IE window exists, navigate by link text

3) If IE window doesn't exist, open IE, login, navigate by link text

That's it.

I know there's a straightforward way to do this, and with time I'd hopefully figure it out. But if you guys could speed this simple process up for me, I'd really appreciate it. Thanks!

Share this post


Link to post
Share on other sites



In your script, you're using

$oIE = _IECreate($testsite)

Use this instead:

_IENavigate ( ByRef $o_object, $s_url [, $f_wait = 1] )

Share this post


Link to post
Share on other sites

galpha:

Thanks for such a quick reply. I was aware of the _IENavigate function, but I'm still unclear as to how to utilize it while still leaving the $oIE function to create a new IE window if one isn't already open.

If you've got a minute and could dummy up some code, it would help me.

Thanks.

Share this post


Link to post
Share on other sites

Do you want to reuse *any* existing IE instance or just one that happens to be on $testsite ??

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

Dale:

These tests will be run in a controlled environment, so there will only ever be one instance of IE running on these test machines. So, for my purpose, I can refer to any instance...but to be more efficient, I'd like to know how to refer to just the $testsite window.

Does that help?

Share this post


Link to post
Share on other sites

One suggestion would be to use the Try Attach parameter for _IECreate and pass your URL -- if it finds a browser at that URL it will use it and attach to it.

Note, if you are using Vista, please see the link in my Sig for issues and workarounds with issues caused by new security restrictions.

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

One suggestion would be to use the Try Attach parameter for _IECreate and pass your URL -- if it finds a browser at that URL it will use it and attach to it.

Note, if you are using Vista, please see the link in my Sig for issues and workarounds with issues caused by new security restrictions.

Dale

Dale:

That's what I'm going to do. It's still not technically the fix I was hoping for, but it will suffice. At the tail of each script I'm going to drive the browser to a fixed URL so that each successive script can use the Try Attach from that location.

If you come up with a better solution, please message me. I'll keep an eye on this thread, as well. Thanks for the help!

Chris

Share this post


Link to post
Share on other sites

_IEAttach has lots of options on how to attach to an existing window.

For example,

$oIE = _IEAttach(" - ", "windowtitle")

would be guaranteed to attach to the first one it found...

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

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