Forum Discussion

kish's avatar
kish
Contributor
13 years ago

How to click on a label/link exist in a row?


Hi,


I have written a script to click on a link exist in each row (first column entry)
in a table. Attached the screen shot.


If i run this script , it is always selecting the first
entry. Kindly suggest any changes to my script?


function orderdetails(y)

  {

  var j;

   order = Aliases.IEXPLORE.pageCustomerorderdetails.panelCtl00MG8b2deec601ca48898630_1.tableCtl00MG8b2deec601ca48898630;



   var ordercount = order.RowCount-1;

   Log.Message(ordercount);

  for(j=1; j<=ordercount; j++)

  {

      Log.Message(j);

     orderslink = order.cell(j, 0);

    

  Log.Message(y);



 Log.Message(orderslink.innerText);





    if((orderslink.innerText)== "Test 1")



   {


var PropArray, ValuesArray, w;

   PropArray = new Array("innerText");

  ValuesArray = new Array("Test 1");



w =  orderslink.FindChild(PropArray, ValuesArray, 5);

    Delay(3000);

    w.Click();

    Aliases.IEXPLORE.pageCustomerorderdetails.linkClose.Click();

    Delay(3000);

    }

 

  }    

  }


Many Thanks,


Kish

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The problem is that you have MANY orders all with the same label, "Test 1".  You're then using a method, FindChild, that will find one item with the matching criteria.  Usually, it will return the first of many items.



    If your intent is to go down the list and click on each order, one at a time, and close the resulting window, your better code would be to use FindAllChildren which will return all links in the table in an array that you can then iterate through with a for loop.



    Code below is untested, but this SHOULD give you wnat you want.



    function orderdetails(y)





    {

        var j;

        order = Aliases.IEXPLORE.pageCustomerorderdetails.panelCtl00MG8b2deec601ca48898630_1.tableCtl00MG8b2deec601ca48898630;

        var ordercount = order.RowCount-1;

        Log.Message(ordercount);

        var PropArray, ValuesArray, w; 

        PropArray = new Array("innerText");

        ValuesArray = new Array("Test 1");

        var LinkArray = order.FindAllChildren(PropArray, ValuesArray, 5);

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

        var LinkIndex;

        for(LinkIndex=0;LinkIndex<LinkArray.length;LinkIndex++)    

        {

            Log.Message(LinkIndex+1);

            Log.Message(y);

            Log.Message(LinkArray[LinkIndex].innerText);

            LinkArray[LinkIndex].Click();

            Aliases.IEXPLORE.pageCustomerorderdetails.linkClose.Click(); 

            Delay(3000);

        } 

      

    }
     
  • kish's avatar
    kish
    Contributor
    Hi Martin,



    Thanks for your help.

    I have tried with your code. If i run the script , it is always clicking on the last row entry.



    Regards,

    Kish


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The possibility could be, then, that there is only the one link that matches the criteria passed into FindAllChildren.  You'll most likely need to use Object Spy to inspect the different links.  It sounds like, perhaps, there's other data in the 'innerText' property that is excluding the other links.



    The code I put up should work so long as each link you want to click on has an innerText of "Test 1".  If LinkArray.length = 1 then it will only ever click the one link... you need to pass criteria in that will return all of the desired links.