Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..
354 views

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);

tabletabletable cont..table cont..

0 Likes
5 Replies
Highlighted
Micro Focus Contributor
Micro Focus Contributor

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

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

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

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

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.

 

 

0 Likes
Highlighted
Micro Focus Contributor
Micro Focus Contributor

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

Hi

Which browser is used ?

Thanks,

Michal

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

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

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

0 Likes
Highlighted
Micro Focus Contributor
Micro Focus Contributor

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

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

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.