Jump to content

IE.au3, clicking, javascript, and tables


NATO
 Share

Recommended Posts

Hi there,

I'm writing a script to test a website by filling out some forms and navigating the site. I've run into an issue, though, where I'm trying to click a cell within a table. There is no <a> (anchor) tag within the cell--instead, the entire cell is link by way of javascript. Unfortunately, I have no control over this or I would certainly change it in a heartbeat. Here's the sample HTML for the table cell from the website:

<TD class=erisMenuItem id=menuLeft5 onmouseover=MenuOverOut(this,1); onclick='MenuClicked("menuLeft5");SubmitChild("tsgGeneralInfo",this)' onmouseout=MenuOverOut(this,2);>General Info</TD>

As you can see, there is a CSS class associated with it, an ID, and lots of javascript actions. Ignoring all of that, there is only some basic text within the cell that says "General Info".

So, I've scripted up to this point using this code:

...other code...

$oIE = _IECreate ("xxxWebsiteHerexxx")
$oFrame = _IEFrameGetObjByName($oIE,"frameDetail")
$oForm = _IEFormGetObjByName ($oFrame, 'Form1')
$oInputs = _IETagNameGetCollection ($oForm, "td")

For $oInput In $oInputs
    If (StringRegExp($oInput.innerHTML,'General Info')) Then
        $begin = TimerInit()
        _IEAction($oInput,"click")
                MsgBox(0,'','found it!')
        ExitLoop
    EndIf
Next

_IELoadWait($oFrame)

...more code...

As you can see, I've created an IE instance, found the frame and form, and then got a collection of all TD tags. I step through the TD tags until I find the one that says "General Info" inside of it. I call the _IEAction() function to 'click' the TD, then pop-up a message box so that I'm sure it found it, and whammo---nothing happens on the web page.

It looks like _IEAction() can't click a TD...

Any suggestions??

Thanks in advance!

Link to comment
Share on other sites

_IEAction most certainly can click on a TD. Chances are there is something else going on... like perhaps a need to also fire the onmouseover event...

Also, you should be able to get a reference to the table cell directly without needing to loop through the collection with $oTD = _IEGetObjByID($oIE, "menuLeft5")

You can fire other events with something like this:

$oTD.fireEvent ("onmouseover")

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

Link to comment
Share on other sites

_IEAction most certainly can click on a TD. Chances are there is something else going on... like perhaps a need to also fire the onmouseover event...

Also, you should be able to get a reference to the table cell directly without needing to loop through the collection with $oTD = _IEGetObjByID($oIE, "menuLeft5")

You can fire other events with something like this:

$oTD.fireEvent ("onmouseover")

Dale

Thanks for the suggestion! The 'onmouseover' event looks to just re-assign a class name to the TD, which just affects highlight color for the hover effect. I tried adding this, though, and it didn't seem to make a difference: $oTD.fireEvent("onclick")

I added it just before the _IEAction($oTD,"click").

Unfortunately, my script runs to completion without so much as an error after doing the above--but the web page never goes on to another page!

Am I missing something? Would you like to see the javascript code, perhaps? :-\

Link to comment
Share on other sites

I would have to see the Javascript and the full HTML.

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

Link to comment
Share on other sites

I would have to see the Javascript and the full HTML.

Dale

Thanks for being so helpful! The code for this page is awful, but unfortunately, I don't have the kind of pull in my company to get it rewritten. Here's the navigation frame's HTML & java script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>Liberty Quote</title>
        <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
        <meta content="C#" name="CODE_LANGUAGE">
        <meta content="Javascript" name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        <LINK href="../common/erisNETStyles.css" type="text/css" rel="stylesheet">
<script language="Javascript" src="../common/commonFunctions.js"></script>
        <script language="Javascript" src="common/frame.js"></script>
        </SCRIPT>
    </HEAD>
    <body id="Body" leftMargin="0" topMargin="0">
        <form name="Form1" method="post" action="tsgFrame.aspx?src=tsgWatercraft" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDwyMDk4NDY0ODg4O3Q8O2w8aTwzPjs+O2w8dDw7bDxpPDE+Oz47bDx0PDtsPGk8MT47aTwzPjs+O2w8dDw7bDxpPDA+Oz47

bDx0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8UExQOz4+Oz47Oz47Pj47Pj47dDxwPGw8c3JjOz47bDxQQ1AvdHNnV2F0

ZXJjcmFmdC5hc3B4Oz4+Ozs+Oz4+Oz4+Oz4+Oz7dHfzX4R7FCPFGRTkYwyy572THVQ==" />
    
<script LANGUAGE='Javascript'>
<!--
function SubmitChild(page,theMenu){var  blnSave=true;var theCurrentMenu=document.forms[0].hidCurrentLeftMenu.value;if(theCurrentMenu==page) return;if(theCurrentMenu=='') return;if(iFrameBody.IfValueChangedInPage()){var theButton = eval(iFrameBody.Form1.btnSave);if(!theButton) {theButton = eval(iFrameBody.Form1.btnSaveAndExit);}if(theButton){var theField = eval(iFrameBody.Form1.hidPageToMove);if(theField){if(confirm('Do you want to save the current page information?')){iFrameBody.Form1.hidPageToMove.value=page;theButton.click();}else blnSave = false;}}else blnSave = false;}else blnSave = false;if(!blnSave){if(page=='tsgLogin'){parent.window.location.href = 'tsgLogin.aspx';}else{iFrameBody.location.href = 'PCP/'+page+'.aspx'}document.forms[0].hidCurrentLeftMenu.value=page;}}function RedirectToTop(page){var theField=eval('document.forms[0].hidCurrentLeftMenu');var blnSave=true;if(theField){if(theField.value.length>0){if(iFrameBody.IfValueChangedInPage()){var theButton = eval(iFrameBody.Form1.btnSave);if(!theButton) {theButton = eval(iFrameBody.Form1.btnSaveAndExit);}if(theButton){if(confirm('Do you want to save the current page information?')){iFrameBody.Form1.hidPageToMove.value=page+'&top=y';theButton.click();}else blnSave = false;}}else blnSave = false;}else blnSave = false;}else blnSave = false;if(!blnSave){if(page=='tsgLogin'){parent.window.location.href = 'tsgLogin.aspx';}else{parent.frameDetail.location.href = 'tsgFrame.aspx?src='+page+'&top=y'}document.forms[0].hidCurrentLeftMenu.value=page;}}// -->
</SCRIPT>

    
<script LANGUAGE='Javascript'>
<!--
function menuID(id){this.id = id;}var allMenu = new Array();allMenu['tsgCustomer'] = new menuID('menuLeft1');allMenu['tsgResidence'] = new menuID('menuLeft2');allMenu['tsgVehicles'] = new menuID('menuLeft3');allMenu['tsgWatercraft'] = new menuID('menuLeft4');allMenu['tsgGeneralInfo'] = new menuID('menuLeft5');allMenu['../tsgBillingInfo'] = new menuID('menuLeft6');allMenu['../tsgAuthentication'] = new menuID('menuLeft7');var menuCount=7;// -->
</SCRIPT>


            <TABLE id="Table1" height="100%" cellSpacing="0" cellPadding="0" width="804" border="0">
                <TR>
                    <TD id="trLeftMenu" class="erisHighLight" valign="top">
<script language="javascript">
var CurrentMenu=false;
function MenuOverOut(theCtl,action){if(CurrentMenu!=theCtl.id){var className='erisMenuItemOver';if(action == 2)className='erisMenuItem';theCtl.className=className;}}
function MenuClicked(which){var theCtl='';if(menuCount>1){for(i=1;i<=menuCount;i++){theCtl = eval('document.all["menuLeft'+i+'"]');if(theCtl){theCtl.className='erisMenuItem';}}}theCtl = eval('document.all["'+which+'"]');if(theCtl){theCtl.className='erisMenuItemOver';}CurrentMenu=which;}
function SelectCurrentMenu(){
    var theCurrentMenu= eval('document.all["hidCurrentLeftMenu"]');
    if(theCurrentMenu){
        var theCurrentMenuName=theCurrentMenu.value;
        //alert(theCurrentMenuName)
        if(allMenu[theCurrentMenuName] != null)
        {
            CurrentMenu=allMenu[theCurrentMenuName].id;
            theCtl = eval('document.all["'+CurrentMenu+'"]');
            if(theCtl)theCtl.className='erisMenuItemOver';
        }
    }
}
</script>
<TABLE id="TableLeftMenu" align="left" class="TableLeftMenu" cellSpacing="0" cellPadding="0"
    border="0">
    <TR>
        <TD style="HEIGHT: 19px" width="138">&nbsp; <FONT class="erisWhiteBold">
                <span id="leftMenu_lblLOB" class="erisWhiteBold">PLP</span>
            </FONT>
        </TD>
    </TR>
    <tr>
        <td vAlign="top" height="300">
            <table class='erisMenuGroup' cellspacing='0' id='menuLeftGroup' width='100%' cellpadding='0' border='0'style='z-index:999;'><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft1");SubmitChild("tsgCustomer",this)' id='menuLeft1'>Customer</td></tr><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft2");SubmitChild("tsgResidence",this)' id='menuLeft2'>Coverage and Personal</td></tr><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft3");SubmitChild("tsgVehicles",this)' id='menuLeft3'>Automobile</td></tr><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft4");SubmitChild("tsgWatercraft",this)' id='menuLeft4'>Watercraft</td></tr><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft5");SubmitChild("tsgGeneralInfo",this)' id='menuLeft5'>General Info</td></tr><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft6");SubmitChild("../tsgBillingInfo",this)' id='menuLeft6'>Billing Info</td></tr><tr><td class='erisMenuItem' onmouseover='MenuOverOut(this,1);' onmouseout='MenuOverOut(this,2);' onclick='MenuClicked("menuLeft7");SubmitChild("../tsgAuthentication",this)' id='menuLeft7'>Application Authorization</td></tr></table>
        </td>
    </tr>
    <tr>
        <td align="center" valign="top">
            <P>
                <FONT class="erisWhite">Please do not click your browser's "Back" button</FONT>
            </P>
        </td>
    </tr>
</TABLE>
</TD>

                    <TD vAlign="top" width="100%" height="100%"><iframe id="iFrameBody" style="WIDTH: 100%; HEIGHT: 100%" tabIndex="0" name="iFrameBody" frameBorder="0" scrolling="auto" src="PCP/tsgWatercraft.aspx"></iframe>
                    </TD>
                </TR>
            </TABLE>
        <input name="hidCurrentLeftMenu" id="hidCurrentLeftMenu" type="hidden" value="tsgWatercraft" />
<script LANGUAGE='Javascript'>
<!--
SetInitialFocus();var lob='PU';SetScrollerPosition(0,0);PageInit();

// -->
</SCRIPT>

</form>
    </body>
</HTML>

If you would like to see anything else, just let me know! Thanks again for your willingness to dig deeper into my problem. :)

Link to comment
Share on other sites

Unfortunately, the HTML and script you provide does not render properly. I think the main issue is that the external files commonFunctions.js and frame.js are missing. I therefore cannot see the interaction with the mouse or any events fire.

If you want to PM me a .mht file I should be able to see better.

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

Link to comment
Share on other sites

Unfortunately, the HTML and script you provide does not render properly. I think the main issue is that the external files commonFunctions.js and frame.js are missing. I therefore cannot see the interaction with the mouse or any events fire.

If you want to PM me a .mht file I should be able to see better.

Dale

Done!

Link to comment
Share on other sites

With the information you sent me, the following code that clicks on table cells works fine for me...

#include <IE.au3>

$oIE = _IEAttach("Liberty")
$oFrame1 = _IEFrameGetObjByName($oIE, "frameDetail")

$oTD5 = _IEGetObjById($oFrame1, "menuLeft5")
_IEAction($oTD5, "click")
Sleep(5000)
$oTD4 = _IEGetObjById($oFrame1, "menuLeft4")
_IEAction($oTD4, "click")
Sleep(5000)
$oTD3 = _IEGetObjById($oFrame1, "menuLeft3")
_IEAction($oTD3, "click")
Sleep(5000)
$oTD2 = _IEGetObjById($oFrame1, "menuLeft2")
_IEAction($oTD2, "click")
Sleep(5000)
$oTD1 = _IEGetObjById($oFrame1, "menuLeft1")
_IEAction($oTD1, "click")

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

Link to comment
Share on other sites

With the information you sent me, the following code that clicks on table cells works fine for me...

#include <IE.au3>

$oIE = _IEAttach("Liberty")
$oFrame1 = _IEFrameGetObjByName($oIE, "frameDetail")

$oTD5 = _IEGetObjById($oFrame1, "menuLeft5")
_IEAction($oTD5, "click")
Sleep(5000)
$oTD4 = _IEGetObjById($oFrame1, "menuLeft4")
_IEAction($oTD4, "click")
Sleep(5000)
$oTD3 = _IEGetObjById($oFrame1, "menuLeft3")
_IEAction($oTD3, "click")
Sleep(5000)
$oTD2 = _IEGetObjById($oFrame1, "menuLeft2")
_IEAction($oTD2, "click")
Sleep(5000)
$oTD1 = _IEGetObjById($oFrame1, "menuLeft1")
_IEAction($oTD1, "click")

Dale

Hey, that worked! Huh...I wonder why my code that would find the TD by stepping through the collection of TDs wouldn't click on it. Oh well--you've found a working solution. Thanks so much for your help!

-Nate

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...