TruClient: How to take the No of rows in a table using XML

I am trying to take the row length from a dynamic table, I tried to use the below code to find the length but its not returning the no of rows, any help will be appreciated.

var r;
var x;
r = document.evaluate("//*[@id=\"grid-control10\"]/p-table/div/div/table/tbody/tr",document,null,XPathResult.ANY_TYPE,null);
x = r.length;
alert(x);

Htm1.PNGHtm2.PNG

Parents
  • Hi,

    The return value of document.evaluate is of type XPathResult which does not have the length property.
    You can try this code:

    var r;
    var x;
    r = document.evaluate("//*[@id=\"grid-control10\"]/p-table/div/div/table/tbody/tr",document,null,XPathResult.ANY_TYPE,null);
    var retVal = [], curVal;
    while (curVal = r.iterateNext())
         retVal.push(curVal);
    alert(retVal.length);

     

    Thanks,

    Michal

  • Hi Michal 

    Thanks for the info, but still i am not able to get the no of rows in the table.

    var r;
    var x;
    r = document.evaluate("//*[@id=\"grid-control8\"]/p-table/div/div/table/tbody/tr",document,null,XPathResult.ANY_TYPE,null);
    var retVal = [], curVal;
    while (curVal = r.iterateNext())
    retVal.push(curVal);
    alert(retVal.length);

    In variable r i am only seeing only one object and the retVal length is showing 0.  Can you help me in how to get the whole rows with document.evalutate.

    Absolute Xpath : //*[@id="grid-control8"]/p-table/div/div/table/tbody/tr[1]/td[11]/span/span

    When i use evalXpath, the result shows all the objects in the table but the same i am not able to use it in JavaScript code, it's working only in EvaluateJsonObject.

     

     

  • Hi

    Which browser is used ?

    Thanks,

    Michal

  • Chrome browser.  The current app, which i am working only works in Chrome.

Reply Children
  • Hi,

    Your code seems to be correct. The only difference i can see is that previously the id was grid-control10 and now it is grid-control8. Maybe this is the issue?
    Try to copy the XPATH from devtools in chrome and see if it the same.

    One more thing that can be is the table is under a Shadow Dom which is encapsulated Dom inside the global document. In that case the document.evaluate will not work.
    You can see if that is the case by enabling “Show user agent Shadow DOM” in the devtools settings, inspect the element and see if it is under “shadow root”

    Please let me know,

    Regards,

    Michal