Sign in to follow this  
Followers 0
kylek29

Focus on GUI Browser Window

14 posts in this topic

#1 ·  Posted (edited)

At work we run Cognos reports, which requires input (same thing, every day). I unsuccessfully tried to use the IE.au3 controls to get set the form data automatically (it uses Javascript, so the form data is getting a mismatch, even using the names provided by IEBuilder and through my own reading of the sourcecode), so now I am trying to make it so that it tabs through the options, setting them as it goes, then hits finish.

I got it to do it in an IE7 window, but I'd like to do it in its own window. Read a lot of scripts and this is what I have so far (not clean yet):

#include <GUIConstants.au3> 
#Include <ie.au3> 

$Name = "***"

$BrowsWin = GUICreate("Simple Web Browser MINI Version", 1270, 1020, 1, 1) 
$IEWin = ObjCreate("Shell.Explorer.2") 
$IEWinCtrl = GUICtrlCreateObj($IEWin, 0, 0, 1024, 768)
GUICtrlSetState(-1,$GUI_ENABLE)

_IENavigate($IEWin, ".....") 

WinSetTitle($BrowsWin, "", "" & _IEPropertyGet($IEWin, "title"))
WinWaitActive("Labor Hours by Agent  Subtotal by Date - Cognos Viewer")

--Based off Simple Web Browser Mini Script--

However, it sets the focus to the master GUI and not the browser object. So you have to mouse click in the browser window for the script to do the tabbing. I'd like to eliminate that function so it goes right through.

And now ...

Second part is a bunch of tabs and inserting. The objectlist for the FORM is in "FIRST LAST" like that. I've tried to send just the exact name in one Send() function, but it goes right to just the first person in the list with the first name that matches .. for example:

List has:

John Doe

John Doh

John Doe2

John Doe3

John Dozer

Send("John Doh")

It'll select the first John in the list it finds, this being "John Doe". I've also tried sending the letters individually (even with pauses between strokes) and it does the same thing (and "John{SPACE}Doh"). However, in IE, if I select this box and type "J" "O" "H" "N" "*SPACE*" "D" "O" "H" it'll select the right name.

Any ideas on either of these?

Edited by kylek29

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Please edit your post and break that looooong line... :)

As for embedding the IE in a GUI, that looks like this:

#include <GUIConstants.au3>
#Include <ie.au3>

$BrowsWin = GUICreate("Simple Web Browser MINI Version", 1024, 768, 1, 1)
$IEWin = _IECreateEmbedded()
$IEWinCtrl = GUICtrlCreateObj($IEWin, 10, 10, 1004, 748)
_IENavigate($IEWin, "about:blank")
GUICtrlSetState()

_IENavigate($IEWin, "http://cognosbi/cognos8/cgi-bin/cognosisapi.dll" & _
        "?b_action=xts.run&m=portal/report-viewer.xts" & _
        "&ui.action=run&ui.object=%2fcontent" & _
        "%2fpackage%5b%40name%3d%27Epiphany" & _
        "%27%5d%2ffolder%5b%40name%3d%27Time%20Reports" & _
        "%27%5d%2freport%5b%40name%3d%27Labor%20Hours%20by%20Agent" & _
        "%20%e2%80%93%20Subtotal%20by%20Date%27%5d" & _
        "&ui.backURL=%2fcognos8%2fcgi-bin%2fcognosisapi.dll" & _
        "%3fb_action%3dxts.run%26m%3dportal%2fcc.xts" & _
        "%26m_folder%3diD7F4342AB37C480FA5779DE14EB5BCB5")

WinSetTitle($BrowsWin, "", "" & _IEPropertyGet($IEWin, "title"))
GontrolFocus($BrowsWin, "", $IEWinCtrl)

With all the power available in the IE.au3 UDF, I would hope you don't have to resort to blind "Send()" functions to enter the data. But I don't have "Cognos" to test against.

;)

Edit: Almost forgot to add assigning focus to the IE embedded

Edit 2: ...and then added it wrong... :">

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

With all the power available in the IE.au3 UDF, I would hope you don't have to resort to blind "Send()" functions to enter the data. But I don't have "Cognos" to test against.

:)

Edit: Almost forgot to add assigning focus to the IE embedded

Removed the string. It's a little annoying to work that long string anyways. I was hoping to get it to work with just the IE.au3 stuff. It seems to work well with most things. But the form output of Cognos is rather cluttered. Thanks btw for the code. Using AutoIt3 to "Detect text" on the Window shows blank (even though there is text). Ultimately, my goal is to set it up to get it to pass the name right so that anyone could use it (as long as they configure their name right in an .INI file), not just me. But right now, I have to have it find my first name, then down-key X amount of times til it reaches my name.

The main problem with Cognos and IE UDF is that Cognos changes it's form names every refresh (so every load of that page). For example, the finish button on one load:

name="finishN1222BE38x0BB571F0"

and after a reload ...

name="finishN0ACA5200x128A5668"

So unless there is another way to find that button (or listbox/etc), it's a no go. Short of looking for something that says "finishN*".

Edited by kylek29

Share this post


Link to post
Share on other sites

Hmm, getting an unknown function name on GUICtrlSetFocus.

P:\Tools\AutoIt3\Old Scripts\browser.au3(22,42) : ERROR: GuiCtrlSetFocus(): undefined function.
GuiCtrlSetFocus($BrowsWin, "", $IEWinCtrl)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
P:\Tools\AutoIt3\Old Scripts\browser.au3 - 1 error(s), 0 warning(s)

AutoIt Version 3.2.4.9

Share this post


Link to post
Share on other sites

Hmm, getting an unknown function name on GUICtrlSetFocus.

P:\Tools\AutoIt3\Old Scripts\browser.au3(22,42) : ERROR: GuiCtrlSetFocus(): undefined function.
GuiCtrlSetFocus($BrowsWin, "", $IEWinCtrl)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
P:\Tools\AutoIt3\Old Scripts\browser.au3 - 1 error(s), 0 warning(s)

AutoIt Version 3.2.4.9

To quote the sage philosopher Homer...

DOH! :)

That should be ControlFocus(), not GuiCtrlSetFocus().

:">


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Removed the string. It's a little annoying to work that long string anyways. I was hoping to get it to work with just the IE.au3 stuff. It seems to work well with most things. But the form output of Cognos is rather cluttered. Thanks btw for the code.

You're welcome... thanks for debugging it for me! ;)

Using AutoIt3 to "Detect text" on the Window shows blank (even though there is text).

That's normal in an IE window (even an embedded one).

Ultimately, my goal is to set it up to get it to pass the name right so that anyone could use it (as long as they configure their name right in an .INI file), not just me. But right now, I have to have it find my first name, then down-key X amount of times til it reaches my name.

The main problem with Cognos and IE UDF is that Cognos changes it's form names every refresh (so every load of that page). For example, the finish button on one load:

name="finishN1222BE38x0BB571F0"

and after a reload ...

name="finishN0ACA5200x128A5668"

So unless there is another way to find that button (or listbox/etc), it's a no go. Short of looking for something that says "finishN*".

That's not a problem with functions like _IEFormElementGetCollection() and _IEFormElementGetObjByName().

If you take some time to work out the document model you shouldn't have any trouble with it.

First things first: Does the code I gave you open the Cognos page in an embedded IE window?

If so, you next want to get a dump of the HTML for that page. You can do that by adding this to the script after the page loads:

$sHTML = _IEBodyReadHTML($IEWin)
ConsoleWrite("Debug: HTML:" & @LF & $sHTML & @LF)

$colForms = _IEFormGetCollection($IEWin)
$iCntForms = @extended
ConsoleWrite("Debug: There are " & $iCntForms & " forms on this page." & @LF)
If $iCntForms Then
    $i = 0
    For $oForm In $colForms
        ConsoleWrite("Debug: Form " & $i & ": " & $oForm.name & @LF)
        $i += 1
    Next
EndIf

Post the results from the console of SciTE (purge any private data like real names, phone numbers, etc. that might show up).

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The results from the console may be a tad long, here is just a fraction (stripped out names, left the admin users for reference), the actual table containing the names:

<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD><SELECT class=clsListControl id=selectList_P142 style="WIDTH: auto" onchange="setTimeout('listBox_P142.checkData()', 100)" multiple size=11 name=_oLstChoices_P142><OPTION value="ADMIN USER (ADS)">ADMIN USER (ADS)</OPTION><OPTION value="Admin User (LDAP)">Admin User (LDAP)</OPTION> </SELECT></TD></TR>
<TR>
<TD>
<DIV class=clsFeedbackWidgetParseErrorArrowLeft id=feedback_P142 style="MIN-WIDTH: 200px; WIDTH: 100%"><IMG class=clsFeedbackSpacer height=3 alt="" src="http://cognosbi/cognos8/prompting/reportskin/prompting/images/spacer.gif" width="100%" name=sizer_P142></DIV></TD></TR>
<TR id=selectListBottomRow_P142>
<TD style="WIDTH: 100%" align=right><A class=clsLink href="java script:listBox_P142.selectAll()"><NOBR style="VERTICAL-ALIGN: super; TEXT-ALIGN: right">Select all</NOBR></A>&nbsp;<A class=clsLink href="java script:listBox_P142.deSelectAll()"><NOBR style="VERTICAL-ALIGN: super; TEXT-ALIGN: right">Deselect all</NOBR></A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FIELDSET></DIV>
<script>
            genSelectValueHTML("_P142", 'formWarpRequest', "Agent Name", 'XML', 'prompt', 'listBox', "agent_name", RANGE_NO_VALUE, false, true, false, false, false, true, false, "",null, 2827);listBox_P142.addOptions(["ADMIN USER (ADS)","ADMIN USER (ADS)"],["Admin User (LDAP)","Admin User (LDAP)"],["Admin User (NTLM)","Admin User (NTLM)"],[null]);</SCRIPT>
</DIV></TD></TR>
<TR class=tableRow>
<TD class=tableCell colSpan=2>
<DIV class=block style="HEIGHT: 7mm"></DIV></TD></TR>
<TR class=tableRow>
<TD class=tableCell style="VERTICAL-ALIGN: top; TEXT-ALIGN: center" colSpan=2>
<FIELDSET class=clsFieldSet><BUTTON class=bp id=cancelN0E381650x0DDF0694 onmouseover="" style="FONT-WEIGHT: bold; FONT-SIZE: 8pt" onclick='promptButtonCancel("")' onmouseout="" name=cancelN0E381650x0DDF0694>Cancel</BUTTON></FIELDSET>
<script>
            var promptButtoncancelN0E381650x0DDF0694 = new CPromptButton (document.getElementById("cancelN0E381650x0DDF0694"), PROMPTBUTTON_CANCEL, true);
            pageNavigationObserverArray = pageNavigationObserverArray.concat("promptButtoncancelN0E381650x0DDF0694");
            notify();
    </SCRIPT>

<FIELDSET class=clsFieldSet><BUTTON class=bp onkeypress="return preventSubmitEvent(event);" id=finishN0E381650x0DDF06C0 onmouseover="" style="FONT-WEIGHT: bold; FONT-SIZE: 8pt" disabled onclick=promptButtonfinish() onmouseout="" name=finishN0E381650x0DDF06C0>Finish</BUTTON></FIELDSET>
<script>
            var promptButtonfinishN0E381650x0DDF06C0 = new CPromptButton (document.getElementById("finishN0E381650x0DDF06C0"), PROMPTBUTTON_FINISH, true);
            pageNavigationObserverArray = pageNavigationObserverArray.concat("promptButtonfinishN0E381650x0DDF06C0");
            notify();
    </SCRIPT>
</TD></TR></TBODY></TABLE>

Overall code for this single page is 425 lines.

As far as the GUICtrlFocus, I kinda figured you meant ControlFocus, so I switched to that. It still won't Focus on that particular window, I still have to click within the window to get tabbing to work. Kinda strange. If I run it pointed to an IE7 window (full GUI), it puts focus on the address bar which I can tab out of to the items on the page.

Edited by kylek29

Share this post


Link to post
Share on other sites

The results from the console may be a tad long, here is just a fraction (stripped out names, left the admin users for reference), the actual table containing the names:

<snip>

Overall code for this single page is 425 lines.

As far as the GUICtrlFocus, I kinda figured you meant ControlFocus, so I switched to that. It still won't Focus on that particular window, I still have to click within the window to get tabbing to work. Kinda strange. If I run it pointed to an IE7 window (full GUI), it puts focus on the address bar which I can tab out of to the items on the page.

On the focus, an embedded IE doesn't have an address bar and maybe that has something to do with it. Once we get the object reference to what you're interested in, you can do _IEAction($oElement, "focus") and that might get it.

Towards that end, what you want access to seems to be in a table, so you want code to get that object first. That table might be in a Form, Frame, or iFrame to boot, and you didn't post the part of the code that would show that.

For instance, did you get an output from this line?

ConsoleWrite("Debug: There are " & $iCntForms & " forms on this page." & @LF)oÝ÷ Ù8b²h Ú+(!¶z-+ÞÊ­i¹^wè¦[ |¨º»®*miû^®Ø^¥¨±«­¢+ØÀÌØí½±Q±Ìô}%Q±Ñ
½±±Ñ¥½¸ ÀÌØí%]¥¸¤(ÀÌØí¥
¹ÑQ±Ìôáѹ)
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèQ¡ÉÉÅÕ½ÐìµÀìÀÌØí¥
¹ÑQ±ÌµÀìÅÕ½Ðìѱ̽¸Ñ¡¥ÌÁ¸ÅÕ½ÐìµÀì1¤)%ÀÌØí¥
¹ÑQ±ÌQ¡¸($ÀÌØíÐôÀ(%½ÈÀÌØí½Q±%¸ÀÌØí½±Q±Ì($%
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèQ±ÅÕ½ÐìµÀìÀÌØíеÀì1¤($$ÀÌØí½±I½ÝÌô}%Q9µÑ
½±±Ñ¥½¸ ÀÌØí½Q±°ÅÕ½ÐíQHÅÕ½Ðì¤($$ÀÌØí¥
¹ÑI½ÝÌôáѹ($%
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèQ¡ÉÉÅÕ½ÐìµÀìÀÌØí¥
¹ÑI½Ý̵ÀìÅÕ½ÐìɽÝÌ¥¸Ñ¡¥Ìѱ¸ÅÕ½ÐìµÀì1¤($%%ÀÌØí¥
¹ÑI½ÝÌQ¡¸($$$ÀÌØíÈôÀ($$%½ÈÀÌØí½I½Ü%¸ÀÌØí½±I½ÝÌ($$$%
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèI½ÜÅÕ½ÐìµÀìÀÌØíȵÀìÅÕ½ÐìèÅÕ½ÐìµÀìÀÌØí½I½Ü¹%¹¹ÉQáеÀì1¤($$%9áÐ($%¹%($$ÀÌØíЬôÄ(%9áÐ)¹%

This might not work if the table is in a form, but you didn't show that info.

The process is to whittle down the whole DOC down to the form (or frame, etc.), then to the table, then to the object in the table. Once you get that object reference you can do all kinds of magic!

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

:)

I appreciate the help on this. Here is the table output. It's long, names were marked with **NAMES REMOVED**.

table_log.txt

Share this post


Link to post
Share on other sites

I appreciate the help on this. Here is the table output. It's long, names were marked with **NAMES REMOVED**.

From the text file:

Debug: There are 19 tables on this page.

So the code you have can see the table fine. So far, so good.

Debug: There are 51 rows in this table.

Debug: Row 0: 0

Debug: Row 0: 0

Debug: Row 0: Labor Hours by Agent Subtotal by Date Prompt Page

Doh! I left out the increment for $r, making all the rows 0...

If $iCntRows Then
            $r = 0
            For $oRow In $colRows
                ConsoleWrite("Debug:           Row " & $r & ": " & $oRow.InnerText & @LF)
                $r += 1 ;  <--- This increment was missing
            Next
        EndIf

Still, there should be enough info to see which table is the one you are interesed in, and to see if it is consistently the same one. Have you identified the table(s) of interest by index number based on this info? The 19 tables are numbered 0 thru 18, and if they come up the same way consistently you can just use that index number to get the object for that table.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

From looking over the new log (reran with that new parameter you added). From what I get, it shows up in multiple tables, so I'm assuming the debugger is reading everything within a table (table within a table, etc) as the tables get smaller row wise until we reach Table 18 which is the final table, and the one containing the names (makes since, layout wise for this page).

Now, what would I use to interact with that? I did fix my selection problem (of it not sending the names correctly via send), so if I get the focus on that box, the rest is easy.

Share this post


Link to post
Share on other sites

From looking over the new log (reran with that new parameter you added). From what I get, it shows up in multiple tables, so I'm assuming the debugger is reading everything within a table (table within a table, etc) as the tables get smaller row wise until we reach Table 18 which is the final table, and the one containing the names (makes since, layout wise for this page).

Now, what would I use to interact with that? I did fix my selection problem (of it not sending the names correctly via send), so if I get the focus on that box, the rest is easy.

When you do _IETableGetCollection() above, you get a collection of ALL the tables. Now that you know which one you really wanted, you just get it by specifying the (0-based) index:

$oTable = _IETableGetCollection($oIE, 18)oÝ÷ Ù8Z¶Öéh¢G)¶¬|¨º¹hÞ'¯yÊx7º|M¦å{_y» çÄáz·­íë£"Øb²ÖàÞnè9ñ0Ó
ÁDCT@Ãy» çÄhÃ^|Ð7º|F6çÄç-jYCzÇ¥yËZ_ܡף
)®Ún¡iÖºw!¡ùmL8-ßÓij*ìjº.Ûazv¦z̨º·¦¢÷F5¬¡j÷yéÚ)ì!Èp¢é]{ej)íí£
¢{Z{0«b²èm¦åÊÜ(ÔÃÚZ»®§u§(º^¡öî¶Ú'±gjwkY]£    í¢Øh±æî¶Ú'²X¤zØb±«­¢+ØÀÌØí½Q±ô}%Q±Ñ
½±±Ñ¥½¸ ÀÌØí½%°Äà¤(ÀÌØí½I½Üô}%Q9µÑ
½±±Ñ¥½¸ ÀÌØí½Q±°ÅÕ½ÐíQHÅÕ½Ðì°È¤(ÀÌØí½±Qô}%Q9µÑ
½±±Ñ¥½¸ ÀÌØí½I½Ü°ÅÕ½ÐíQÅÕ½Ðì¤(ÀÌØíQ}
¹Ðôáѹ)
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèQ±ÄàèI½ÜÈè!ÌÅÕ½ÐìµÀìÀÌØíQ}
¹ÐµÀìÅÕ½Ðìѱѱ±ÌÅÕ½ÐìµÀì1¤)%ÀÌØíQ}
¹ÐQ¡¸($ÀÌØí¤ôÀ(%½ÈÀÌØí½Q%¸ÀÌØí½±Q($%
½¹Í½±]É¥Ñ ÅÕ½ÐíÕèQÅÕ½ÐìµÀìÀÌØí¤µÀìÅÕ½ÐìèÅÕ½ÐìµÀì1¤($%
½¹Í½±]É¥Ñ ÅÕ½ÐíÕè%¹¹ÉQáÐèÅÕ½ÐìµÀìÀÌØí½Q¹%¹¹ÉQáеÀì1¤($%
½¹Í½±]É¥Ñ ÅÕ½ÐíÕè!Q50èÅÕ½ÐìµÀìÀÌØí½Q¹¡Ñµ°µÀì1¤($$ÀÌØí¤¬ôÄ(%9áÐ)¹%

That will hopefully kick out a short specific message with just what we need. I don't know for sure, but you might even get the focus you want with just _IEAction($oRow, "focus"), or _IEAction($oTD, "focus").

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That will hopefully kick out a short specific message with just what we need. I don't know for sure, but you might even get the focus you want with just _IEAction($oRow, "focus"), or _IEAction($oTD, "focus").

:)

Looks like you got it. I was able to focus it with _IEAction($oRow,"focus") and after that it was smooth sailing. Thanks a lot on this, you've been a tremendous help.

Share this post


Link to post
Share on other sites

Looks like you got it. I was able to focus it with _IEAction($oRow,"focus") and after that it was smooth sailing. Thanks a lot on this, you've been a tremendous help.

Whoop whoop! :)

You're welcome.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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