Forum Discussion

nitinn's avatar
nitinn
Occasional Contributor
7 years ago

Need help in counting the total no. of elements in a table

Hi,

I am trying to count the no. of elements present in a table and if they are present, I need to click on them.

Suppose 3 elements are present, I need to click on each one of them.

Below is my code:

 

 

function findata()
{
//if (page.FindChildByXPath("//table[contains(@id,'repeaterTable')]//tr//td/a[@class = 'textlink hand']")
let arr = page.EvaluateXPath("//table[contains(@id,'repeaterTable')]//tr//td/a[@class = 'textlink hand']");
if (!strictEqual(arr,null))
{
for (i in arr)
{arr[i].Click();
page.FindChildByXPath("//input[contains(@id,'buttonListReturn')]").Click();
Delay(2000)
i++;
}
}
else
{
Log.Error("Nothing found");
}
}

7 Replies

  • baxatob's avatar
    baxatob
    Community Hero

    Hi,

     

    Looks nice. Did you face any problem running your code?

     

    While finding elements by XPath is relatively slow method, you can also try FindAll () method >>

    • nitinn's avatar
      nitinn
      Occasional Contributor

      I couldn't count the no. of elements. The For loop isn't navigating.Can you find any error in the code?

      • baxatob's avatar
        baxatob
        Community Hero

        Are you sure that xpath is correct? 

         

        Check the size of array using Log.Message(arr.length); 

    • baxatob's avatar
      baxatob
      Community Hero

       

      Also be careful with strictEqual() function:

       

      let arr = new Array();
      strictEqual(arr, null)); // returns false
      strictEqual(arr.length, 0)); // returns true
          

       

      • nitinn's avatar
        nitinn
        Occasional Contributor

        It is working for the first time.Post that its failing.

        My guess is its not looping correctly.I used arr.length & its correctly returning me 4 rows for the table.

        The error is below:

         

         

        Unable to obtain the item's rectangle.