Forum Discussion

Dave_Gorman's avatar
Dave_Gorman
Occasional Contributor
12 years ago

Click on a cell when there are multiple tables

Can anyone explain how this might work? I'm using JavaScript, TestComplete, Web testing, the cells don't have a unique idStr or ObjectIdentifier. I already use this function to click on a table cell when there is only one table. I am very new to programming so "Smart "bear with me haha:




function ClickTableCell(rowIndex, columnIndex) {


 


    var tableCellObject, propertyNames, propertyValues;


 


    WaitForPage();


 


    propertyNames = new Array("RowIndex", "ColumnIndex", "FullName", "ObjectType");


    propertyValues = new Array(rowIndex, columnIndex, "*Table(dataTbl_hdn)*", "Cell");


 


    //search for objects with matching properties


    Sys.Browser("iexplore").Refresh();


    tableCellObject = Sys.Browser("iexplore").FindAll(propertyNames, propertyValues, '20000', 'TRUE');


    tableCellObject = (new VBArray(tableCellObject)).toArray();


 


 


    //click on first matching object


    if (tableCellObject.length > 0) {


        tableCellObject[0].Click();


    } else {


        LogErrorMessage("ClickTableCell: Unable to find table cell");


    }


 


}



Thanks,

Dave

5 Replies

  • Hi Dave,



    I would recommend starting with finding a table.



    var page = Sys.Browser("*").Page("*");

    var table = page.Find('idStr', 'someTableID', 100);

    var neededCell = table.Cell(3, 2);

    cell.Click();



    Alternatively you can search for cell by any property (contentText for example).

    var neededCell  = table.Find(['tagName', 'contentText'], ['td', 'Some Text Inside Cell'], 100);



    Hope it helps.
  • Dave_Gorman's avatar
    Dave_Gorman
    Occasional Contributor
    Thanks everyone.



    I will try these ideas. Unfortunately the site I was testing has been down all week so I'll let you know how it goes. And yes Colin I'll make a poor attempt at comedy whenever I can haha



    -Dave
  • Dave_Gorman's avatar
    Dave_Gorman
    Occasional Contributor
    Thanks Andrey, 



    That leads to another question I have. There are 3 tables on this particular page. I just want to click on a specific cell in one of the tables. The table don't have an idStr or any other unique identifier that I can see other than the contentText which is probably over 1000 characters. There are "panels" that have unique idStr identifiers though. can I identify cells in panels?



    Tks

    Dave
  • Hey Dave,



    The good news is that there are many ways to solve this problem.



    Probably the simplest solution is finding a div (panel) with unique id and work from there.



    Consider the table without unuqie properties inside panel.

    <div id = 'somePanel>

    <table>

    ...

    </table>

    </div>



    var page = Sys.Browser("Firefox").Page("*");

    var uniquePanel = page.Find('idStr', 'somePanel', 100);

    var neededCell = uniquePanel .Table(0).Cell(3, 2);

    Log.Message(neededCell.contentText);

    neededCell.Click();



    Play with it. If doesn't can you post the snippet of html code?



  • Do the columns within the three tables have different headers? Which are static?



    If tables don't have any unique identifiers, I usually end up using something like the number of columns, or column header names ... assuming they are static.



    If the content text starts with the column headers then moves onto the table contents below it, just leave the column header text in place and replace all the actual data text with a wildcard (*). Should work?



    But I agree. Find the table first, then the cell within it. I'd be amazed if you had a panel with a unique identifier within the cell of a table. But you never know ....



    (PS ... doing a bit of testing to supplement the income from the comedy circuit? Much like me with the rally driving ...)