Sign in to follow this  
Followers 0
Prime03

Controlling new IE windows that have opened from clicking links

9 posts in this topic

#1 ·  Posted (edited)

;open IE and navigate to our web app
$Window = _IECreate("Internal Work Web application")

;Sometimes IE asks if you want to allow clipboard access, I assumed this code should work but it simply jumps right through the script while the main window is blank if the window pops up
;I think I can turn this off in IE but it would be preferred to do action on the window, any suggestions?
If WinActive("Internet Explorer", "Do you want to allow this webpage to access your Clipboard?") Then
    Send ("!a")
EndIf

;Get frame and form objects for log in page
$Frame = _IEFrameGetObjByName($Window, "main_frame")
$LoginForm = _IEFormGetObjByName ($Frame, "loginform")

$UserID =  _IEFormElementGetObjByName ($LoginForm, "login")
$Password =  _IEFormElementGetObjByName ($LoginForm, "password")

;Set values and click log in button
_IEFormElementSetValue($UserID, "")
_IEFormElementSetValue($Password, "")

$LoginButton = _IEGetObjById ($Frame, "butt_login")
_IEAction ($LoginButton, "click")

sleep(500)

_IELoadWait ($Window)

;Collect new frame and objects
$Frame = _IEFrameGetObjByName($Window, "main_frame")

;Click on repair order link
$iRepair = _IEGetObjById($Frame, "iRepair_Generic_repair_order")
_IEAction($iRepair, "click")

;Collect frame object and Click on new repair order button
$Frame = _IEFrameGetObjByName($Window, "main_frame")
_IEImgClick ($Frame, "http:///images/icn_new.gif")
sleep(500)

;Get Newinstalled item object and Click 
$NewInstall = _IEGetObjById($Frame, "serial_no_link")

_IEAction($NewInstall, "click")
sleep(500)

;;At this point a new IE window pops and is the main focus.

msgbox(0, "test", "test")
sleep(1000)

When this new IE window is open it prevents anything from being done on the original page that the link was opened from in the background. I have a few problems I've ran into at this point. First, the script seems to stop until the window is closed. The msgbox code below will not execute until I close this IE window that is on top of the page. Second I also will need to be able to control this new IE window, as well as another one that will be opened from this second window. (at this point there are 3 windows open, each with a different title and information, and the most recently opened IE window is the only window that IE will let you click or type in).

I need to _IEAttach to these new windows as they are opened, and I've tried many different ways of using the function, by title, windowtitle, url, and instance, but none have worked. The biggest problem I need to understand is why autoit is pausing/stopping/looping once _IEAction($NewInstall, "click") is performed and the new window is open.

Can anyone help me stir my brain up a bit so I can get passed this?

If I haven't provided enough information please let me know.

Edit: I've found how to disable the clipboard access popup as well and I'm satisfied with forcing users to enable clipboard access.

I believe I'm starting to understand a bit better after inspecting everything a bit closer. Here's some more information.

The new window that pops up is titled "New Installed Item -- Webpage Dialog", and if my understanding is correct, I believe this is what _IEAttach refers to as a 'modal' dialog window. Here some AutoIt information from the windows. I still am unable to test this though since I get stuck every time after clicking on the last link and opening the new dialog window. 

The Primary window that is first opened with Autoit has a class of 'Internet Explorer_Server', once I get to the Repair order page where I click on New Installed item, the Repair order page has the class 'Frame Tab', and once I've clicked on the link to open the window for New installed item, that new window itself also has a class of 'Internet Explorer_Server'. If I use Autoit info on both windows at this point, they both return an Instance of '1' under the basic control tab. 

Here are my 2 window summaries, 

>>>> MAIN Window <<<<
Title:  New Repair Order - Windows Internet Explorer
Class:  IEFrame
Position:   0, 0
Size:   1920, 1036
Style:  0x1ECF0000
ExStyle:    0x00000100
Handle: 0x0000000001A7081A

>>>> Control <<<<
Class:  Frame Tab
Instance:   1
ClassnameNN:    Frame Tab1
Name:   
Advanced (Class):   [CLASS:Frame Tab; INSTANCE:1]
ID: 
Text:   
Position:   0, 55
Size:   1904, 973
ControlClick Coords:    309, 108
Style:  0x54000000
ExStyle:    0x00000000
Handle: 0x0000000002C607E8
>>>> POP OUT Window <<<<
Title:  New Installed Item -- Webpage Dialog
Class:  Internet Explorer_TridentDlgFrame
Position:   510, 170
Size:   1360, 767
Style:  0x96C80000
ExStyle:    0x00000101
Handle: 0x0000000001CE0910

>>>> Control <<<<
Class:  Internet Explorer_Server
Instance:   1
ClassnameNN:    Internet Explorer_Server1
Name:   
Advanced (Class):   [CLASS:Internet Explorer_Server; INSTANCE:1]
ID: 
Text:   
Position:   0, 29
Size:   1344, 700
ControlClick Coords:    863, 263
Style:  0x56000000
ExStyle:    0x00000000
Handle: 0x0000000000E70594
 
 
 
 I'm beginning to think it might be possible that using _IEAction click is waiting for the page to load before continuing although it has already happened, or hasn't happened all together?
Edited by Prime03

Share this post


Link to post
Share on other sites



Hi Prime03

Have a look at >here...


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Pinco thank you for linking me with these discussions.
 

I have just quickly tried using a ControlSend but unfortunately its not actually hitting the button.

I will resort to compiling a second 'opener' script. Interesting solution to a weird problem.

 

Edited by Prime03

Share this post


Link to post
Share on other sites

Hey guys I'm to continue this thread because I've hit another road block!

The web app that I'm scripting is a huge ASP.net application with an SQL database back end. So i'm at a page were I have many fields to input information and search the database for repair orders. I am able to target the objects for the input fields using GetObjByID on the frame object I've created, and use the insert text function to pop in the text, and then click on the search button. 

Now the bottom of my page has a table that contains the returned search data. All of this information is contained in tables it seems, and the specific part of the table row that i'm trying to 'click' on does not have any identifiers. I'm not even able to create an object for the parent table row even though it has an ID.

In the table row ID that is present, it shows it as id="         row1" in IE dev. When I view this object in debug bar, it tells me it has the id="&#13;&#10;   &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;row_1". I am unable to get matches when trying to create an object for this data after numerous attempts. GetObjByID from the Frame does not return a match, this is not a form so I can not use those methods either, I'm pretty stumped. I've tried counting the number of tables on the page to possibly access this by instance, but I get 161 tables returned, so I think this method is a bit too time consuming. Can anyone help me get access to this object so I can _IEAction on it?

Here is a screenshot presenting as much info as I think I can give. 

XcDtMor.png

Share this post


Link to post
Share on other sites

>.... this may be of interest


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Pinco thank you again for giving me somewhere to go from!

I read through some of Dales posts but I will go over that thread thoroughly in the morning when I get a chance to try some new things. 

My concern after skimming Dales posts is that I'm trying to get a hold of an object that exists within a frame, but doesn't have an ID or Name to use either GetObjByID or Name. The table row in the screenshot I posted is an example of a single return search were I only have 1 row, and oddly enough this row DOES have an ID, of  "      row_1" or "&#13;&#10;   &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;row_1" depending on whether I'm looking at the source or using DebugBar. I understand its likely possible to get this element using the instance or index parameter, but because there is so much data on the page I feel trying to manually find it using GetElementCollection is my last resort.

My previous attempts to create an object reference for the ID using GetObjByID that is listed for this table row, (Within the Frame reference object I've already created) always gives me a No Match error code. And more specifically, I exactly need to access the first Table Data element in this Table Row, but the TDs have no ID or Name, just a 'width' and 'class' property.

I feel pretty comfortable now with how the _IE functions work with the DOM after getting as far as I've gotten, but it's possible I have just been attempting to do something incorrectly and haven't noticed it yet(It's only been a  few short days I've been using the IE UDFs!) I will hammer at it some more in the morning and see what my results are and update here. 

Edited by Prime03

Share this post


Link to post
Share on other sites

 

"&#13;&#10;   &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;row_1"

 

Have you tried this?

$sID = @CRLF & "  " & _StringRepeat(@Tab, 11) & "row_1"
_IEGetObjById ($oFrame, $sID )

If that doesn't work, I notice that the row has an assigned class. Perhaps you could use _IETagNameGetCollection to get a collection of rows and then traverse them to find the one with the desired class.

Share this post


Link to post
Share on other sites

also another try to do (just a wild guess)
 inside the table there should be one link for each cell, and maybe the link contains the same string that is displayed inside the cell, if you have this luck, once the table is complete, you could get a collection of the links, and then loop  through the collection, searching for the string within the link that should identify your target link.
at this point you could "click" on that link.
For example:

Do ; wait for the link collection
    Local $oLinks = _IELinkGetCollection($My_frame)
Until IsObj($oLinks) ; when $oLinks IsObj then the collection is ready

Do
    Local $oLinks = _IELinkGetCollection($My_frame) ; refernce to th link collection
    Local $iNumLinks = @extended ; total number of links

    For $oLink In $oLinks ; loop all links
        $GotIt = StringInStr($oLink.href, $TargetString) ; search for the identifier string
        If $GotIt Then
            ExitLoop
        EndIf
    Next
Until $GotIt

_IEAction($oLink, "click") ; click on the target link

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Have you tried this?

$sID = @CRLF & "  " & _StringRepeat(@Tab, 11) & "row_1"
_IEGetObjById ($oFrame, $sID )

If that doesn't work, I notice that the row has an assigned class. Perhaps you could use _IETagNameGetCollection to get a collection of rows and then traverse them to find the one with the desired class.

 

The first example was a nix, but using TagNameCollection did the trick! I wasn't really aware how this function worked until you mentioned it. After trying it a couple times I was a able to narrow down my collection and pinpoint my element using the innertext property to identify it! Awesome trick because I'm going need to do this quite a bit going forward. I feel much more confident now and I'm getting things done quicker :thumbsup: !

$SearchResultTable = _IEGetObjById ($Frame, "_scrollerTop")
Local $oInputs = _IETagNameGetCollection($SearchTable, "TD")
For $oInputs In $oInputs
 MsgBox(0, "Element Info", "Tagname: " & $oInputs.tagname & @CR & "innerText: " & $oInputs.innerText)
 Next

I have found many examples online that use object properties like $var.name or $var.innertext for example. I think it would be really helpful for me if I was aware of more of these properties but I couldn't find anything in the reference that demonstrated these. Does anyone have something that can shed some light on the possibilities?

Thank you Dan and Pinco for your help, I'm moving forward with my project at a steady pace again and have a proof of concept presentation early next week I'm super excited for. 

Edited by Prime03

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