PDA

View Full Version : Need help with events in HTML Table - Excel 2007



ashyankee
04-28-2010, 01:07 PM
Im trying to click on a cell in a Table on a HTML page through excel macro.

I created an ie object and navigated to the page i want.

The page has a table which has 25 cells.. Actually these cells contain names of people. If any of these cells are clicked then that person's details are displayed in another table in the same page.

I identified the table with

ie.document.all.tags("Table").Item(21)

I even found out the cell i need to click in order to display the information.. I did it like this..

ie.document.all.tags("Table").Item(21).Rows(2).Cells(3)

Im trying to click on this cell now.. I tried
ie.document.all.tags("Table").Item(21).Rows(2).Cells(3).click

It didnt work but i didnt get any error too.. I looked in the source code of the page and found out that its coded with mouseup event on those cells.

I tried
ie.document.all.tags("Table").Item(21).Rows(2).Cells(3).mouseup and im getting Object doesnt support this method error.

Anyone knows how to use or fire a mouseup event for this control?

Shred Dude
04-28-2010, 09:04 PM
Is there an href in the source that you could navigate to?

When you do this clicking of a name manually, does the resulting page have a unique URL? If so, can you just build the URL as a string and then navigate to it?



You might also try the Links collection of the document. Can you iterate through that collection to find the correct link, and then click that?

Posting the source would be helpful.

ashyankee
04-28-2010, 10:59 PM
The cells in the table doesnt have any link. The table is populated by some gridrow.. and there are no href tags in any of the cells.. and also the URL doesnt change when clicked on the cell.. it just shows a loading gif and displays the data. all i could see in the source code was the a table and an <input type=hidden id='grid id'>. I found the cell i want to click and just want to know how can i fire a mouseup event in that cell.. Click is not working :(

Sorry i cannot post the source code since im doing this for my boss and that contains all employee data..

Shred Dude
04-29-2010, 08:12 AM
When the mouse up event is fired, what is actually happening? is there a javascript that is being executed? Do you have visibility to the javascript name?

You may be able to call the script with something like this...

Call ie.document.all.tags("Table").Item(21).Rows(2).Cells(3).execScript("mouseup()", "Javascript")

If there's a script name linked to the mouseup event, you may need to try that.

Without seeing the HTML Source its difficult to know for sure. Perhaps you could clean the HTML source of any personal data and provide a sample.

ashyankee
04-30-2010, 03:04 AM
Hey here is the code.. I seriously dont understand what they did with this page.

<tr valign="top">
<td colspan="2" valign="top">
<input type='hidden' id='somegridid' name='somename' value="" />
<table border='0' cellpadding='0' cellspacing='0' id='somegridid' style="overflow:hidden;table-layout:fixed;position:relative;width:100%;heXXht:300px;" class="gridFrameclass" onresize="XXtbl_onResize('somegridid');" onmousemove="XXtbl_tableMouseMove(event,'somegridid');" onmouseup="XXtbl_tableMouseUp(event,'XXl00xXXl00xMainContentPlaceHolderxucxperseneesSe leXXorxgrdxpersones');"><tr id="XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_mr" style="heXXht:100%;"><td id="XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_mc" alXXn='left' style="heXXht:100%;width:100%;vertical-alXXn:top;"><div id="XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_div" style="position:relative;overflow:auto;width:100%;heXXht:100%;" onscroll='XXtbl_onScroll(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' tabIndexPage='0' hideFocus='true'><table id='G_XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones' bandNo='0' border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed;border-collapse:collapse;position:relative;width:100%;position:relative;' onSeleXXStart='XXtbl_seleXXStart(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmousedown='XXtbl_cellClickDown(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmouseup='XXtbl_cellClickUp(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' oncontextmenu='XXtbl_cellContextMenu(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmousemove='XXtbl_cellMouseMove(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmouseover='XXtbl_cellMouseOver(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmouseout='XXtbl_cellMouseOut(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' ondblclick='XXtbl_cellDblClick(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");'><colgroup><col width='18%' /><col width='10%' /><col width='' /><col width='1px' style='display:none;' /></colgroup><thead style='display:none;' onmousedown='XXtbl_headerClickDown(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmouseup='XXtbl_headerClickUp(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmouseout='XXtbl_headerMouseOut(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmousemove='XXtbl_headerMouseMove(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' onmouseover='XXtbl_headerMouseOver(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");' oncontextmenu='XXtbl_headerContextMenu(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones");'><tr><th id='XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_c_ 0_0' columnNo='0' heXXht='24px' class="XX_74bc4db2_r1 gridRow XX_74bc4db2_r4 gridHeader ">&nbsp;</th><th id='XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_c_ 0_1' columnNo='1' heXXht='24px' class="XX_74bc4db2_r1 gridRow XX_74bc4db2_r4 gridHeader ">&nbsp;</th><th id='XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_c_ 0_2' columnNo='2' heXXht='24px' class="XX_74bc4db2_r1 gridRow XX_74bc4db2_r4 gridHeader ">&nbsp;</th><th id='XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_c_ 0_3' columnNo='3' heXXht='24px' class="XX_74bc4db2_r1 gridRow XX_74bc4db2_r4 gridHeader " style="display:none;">&nbsp;</th></tr></thead><tbody style="heXXht:100%"><tr id='XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_r_ 0' style='heXXht:24px;'><td iXX="False" class="XX_74bc4db2_r1 gridRow">

Cell to be clicked..


<td class="XX_74bc4db2_r1 gridRow"><nobr>NAME</nobr></td><td class="XX_74bc4db2_r1 gridRow" style="display:none;"><nobr>ACTIVE</nobr></td></tr><tr id='XXl00xctl00xMainContentPlaceHolderxucxperseneesSelectorxgrdxpersons_r_1 ' style='height:24px;'><td iCT="False" class="XX_74bc4db2_r1 gridRow">


I tried Call ie.document.all.tags("Table").Item(21).Rows(2).Cells(3).execScript(XXtbl_cellClickUp(event,"XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones")... Still throwing error that object doesnot support this property

Shred Dude
04-30-2010, 06:59 AM
That is a mess. Either poor formatting, or an effort to intentionally obscure things.

You have tables within tables. Are you sure your address is truly getting to the element you desire?

Since they give the table row an ID you might try something like:

set myrow = ie.document.getelementbyid("XXl00xXXl00xMainContentPlaceHolderxucxperseneesSeleXXorxgrdxpersones_r_ 0")


Then get to the correct cell, and try the .click approach, although I don't see links. Firing the event is probably the best way. How to do it is the problem.

maybe try the on doubleclick event??...

call myrow.cells(1).execscript("XXl00xXXl00xMainContentPlaceHolderxuc xperseneesSeleXXorxgrdxpersones")

Good luck...

ashyankee
05-04-2010, 04:55 AM
The problem with this page is it doesnt have any javascript.. and i dont know where are these functions called from..

Ex: onmouseout='XXtbl_headerMouseOut(event,"XXl00xXXl00xMainContentPlaceHolderx ucxperseneesSeleXXorxgrdxpersones");'

Must be the stupidest page ever.

Do you know how to call these functions in the page.. I tried what you said but it still shows "Object doesnt support this property".

And i think the table i was trying to access is

<table id='G_ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegate s' bandNo='0' border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed;border-collapse:collapse;position:relative;width:100%;position:relative;' onSelectStart='igtbl_selectStart(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' onmousedown='igtbl_cellClickDown(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' onmouseup='igtbl_cellClickUp(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' oncontextmenu='igtbl_cellContextMenu(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' onmousemove='igtbl_cellMouseMove(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' onmouseover='igtbl_cellMouseOver(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' onmouseout='igtbl_cellMouseOut(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");' ondblclick='igtbl_cellDblClick(event,"ctl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates");'>
<colgroup><col width='18%' /><col width='10%' /><col width='' /><col width='1px' style='display:none;' /></colgroup>

This is the code for the cell im trying to click on <td class="ig_74bc4db2_r1 gridRow"><nobr>Gordon Freeman</nobr></td><td class="XX_74bc4db2_r1 gridRow" style="display:none;"><nobr>Submitted</nobr></td></tr><tr id='XXl00xctl00xMainContentPlaceHolderxucxDelegeteesSelectorxgrdxdelegates_ r_2' style='height:24px;'><td iCT="False" class="XX_74bc4db2_r1 gridRow">

I have no idea where the data is coming from..

ashyankee
05-04-2010, 05:14 AM
The entire document is a form called 'aspnetform'. Should i reference it with ie.document.forms? whats the difference from ie.document.all? Will i be able to fire events in that?