Forum Discussion

yaminiatcs's avatar
yaminiatcs
New Contributor
13 years ago

how to click on particular cell if we dont have its objets, we only have the grid or table objects?

if we have only table object and according to the value we have to find and select that row which contain that value .

























name



number



date



place



bb



ee



hh



kk



cc



ff



ii



ll



 


in this table name , number ...etc are column heading and we want to select the row which contain "kk" of "place" column.

please give me some suggestions in JScript how to perform that operation.




10 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Without knowing your particular component, class, etc., I can't answer that question.  What I posted was simply an example of what you could do but the specifics of what you actually will implement depend upon what your component is.  If your table object does not support the "Cell" property or method, then most likely it is not being seen by TestComplete as a table or grid object or not being seen as one of those objects that is explicitly supported by TestComplete.



    You'll need to inspect your object itself, determine what properties to use, etc., to determine what the abilities are.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Depending upon the class of your object, there should be a property like RowCount or something like that.  Use a "for" loop to loop through the rows, checking that column on each row.  As you loop, keep track of a RowNumber and increment that row number on each time through the loop.  when you find the desired row, "break" out of your loop before you increment your RowNumber.  You now have your row.  Most table objects then have some sort of "cell" property that you can then specify by row and column to interact with cells within the table.  With your row number found and the desired column (in this case, Column 3 since most tables are based upon a zero based numbering), you should have your cell you're looking for.  Something like this in JScript:



    function ClickOnMyCell()

    {

        var RowNumber = 1;

        var LoopIndex

        for(LoopIndex = 1; LoopIndex <= Aliases.MyApp.MyTable.RowCount; LoopIndex++)

        {

            if Aliases.MyApp.MyTable.Cells(LoopIndex, 3).value = "kk"

            {break}

            RowNumber++;

        }

        Aliases.MyApp.MyTable.Cells(RowNumber, 3).Click();

    }




    Very rough code, not tested, but hopefully this demonstrates the principle.
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)
    Hi,



    Robert is right, the way you do this depends on the grid control you are testing.

    You can use either methods and properties provided by TestComplete, or, if you have access to the application's internal objects, use their methods and properties.



    More information is available in the Working With Grids section of TestComplete help.
  • yaminiatcs's avatar
    yaminiatcs
    New Contributor
    Thank you for the suggestion 

    I tried it but Test complete giving error for "Cell" property that this object is not recognize.

    is any other property is there which i can use in place of  "Cell" .
  • cdeng's avatar
    cdeng
    Occasional Contributor

    Issues on working with table Cell 



    I came across with several problems on it.  


    (1) I am able to locate the cell but not able to click.


    (2) On object spy I was able to see the className property but the className became empty during execution on the TC - thus showing on the debug, object evaluation, the className is empty but I can see it on with object spy.

     


    I am using TC 10.40.2015.7 and I have a table in screenshot 1(before click), screeshot(2,3,4) are by different click actions and I want to verify.  I need to check the state of the columes of Yes and the No. Before click and I found the only property change before click and after click is the className. Before click, both of the Yes/No has the the property for the className: selectButton rosYN and the property for the className: selectButton rosYN selected.


     





     


    function verifyChildSystem() {


     


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


        var tblChildSystem = page.Find('idStr','childsystem',100);


        if (tblChildSystem.Exists)   {


          //Goes through the rows and cells of the table


          for (var i = 2; i < tblChildSystem.rows.length; i++) {


            Log.AppendFolder("Row " + i);


            for (var j = 0; j < tblChildSystem.rows.item(i).cells.length; j++)


            //j = 1/2 (yes/no), j = 4/5 (yes/no), j = 7/8 (yes/no)


              if (aqString.GetLength((tblChildSystem.rows.item(i).cells.item(j).innerText))>1){ 


                Log.Message("Cell " + j + ": " + tblChildSystem.rows.item(i).cells.item(j).innerText);


                var btn_InnerText = tblChildSystem.rows.item(i).cells.item(j).innerText;


                var btn_IdStr = tblChildSystem.rows.item(i).cells.item(j).idStr;


                //There is not any Yes/No selected


                //            if (j == 1 || j ==2 || j==4 || j ==5 || j== 7 || j==8)


                if (j == 1 || j==4 || j== 7) {


                    var btnItem = tblChildSystem.rows.item(i).cells.item(j);


                    var btnItemStr = tblChildSystem.rows.item(i).cells.item(j).idStr;


                    bResult=aqObject.CheckProperty(btnItem, "className", cmpEqual, 'selectButton rosYN');


                }


                else if (j ==2 || j ==5 || j==8) {


                    var btnItem = tblChildSystem.rows.item(i).cells.item(j);


                    btnItem = btnItem.Find('ContentText','No',100);


                    bResult=aqObject.CheckProperty(btnItem, "className", cmpEqual, 'selectButton rosYN');


                }


              }


          }    


        }


    }


     


     


    function markShildSystem(iconBS,selectYesNo) {


     


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


        var tblChildSystem = page.Find('ObjectIdentifier','childsystem',100);


        var iconInnerText;


     


        if (tblChildSystem.Exists)   {


          //Goes through the rows and cells of the table


          for (var i = 2; i < tblChildSystem.rows.length; i++) {


            for (var j = 0; j < tblChildSystem.rows.item(i).cells.length; j++) {


                if (aqString.GetLength((tblChildSystem.rows.item(i).cells.item(j).innerText))>1){


                    Log.Message("Cell " + j + ": " + tblChildSystem.rows.item(i).cells.item(j).innerText);


                    iconInnerText = tblChildSystem.rows.item(i).cells.item(j).innerText;


                    if (aqString.StrMatches(iconBS, iconInnerText)) {  //item found


                        if (selectYesNo == 'Yes') {


                         var iconYes = tblChildSystem.rows.item(i).cells.item(j+1) ;


                         iconYes.Click();


     


                        }


                        else {    //No


                          var clickNo=tblChildSystem.rows.item(i).cells.item(j+2);


                          clickNO.Click();


     


                        }  


                        //if the ChildSystem found then exit both of the loops


                        j = tblChildSystem.rows.item(i).cells.length + 1;


                        i = tblChildSystem.rows.length + 1;


                        break;


                    }


                }


            }


          }


        }


     


    }


     


     


    function unittest(){  


        verifyChildSystem(); 


        markShildSystem('Chills','Yes');


     


    }