Community in read only mode June 18 & 19
This community will be set in READ ONLY mode for a while on Tuesday June 18 into Wednesday June 19 while we import content and users from our Micro Focus Forums community site. MORE INFORMATION
garecanbp Contributor.
Contributor.
519 views

Count Xpath

Jump to solution

I have Xpath structure, DomElement//DIV[@class='title-section-conten*'] and it can have multiple descendant

Is there function Count() in XPath that I can use to get the count of the descendant from the object?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Count Xpath

Jump to solution

Yes should be able to do the same thing in Workbench .NET scripts and Visual test as well.

Example in a .NET script:

Dim numberOfDirectChildren = parent.GetChildren().Count

Dim numberOfDescendants = parent.FindAll("//*").Count

0 Likes
3 Replies
Micro Focus Expert
Micro Focus Expert

RE: Count Xpath

Jump to solution

Hi,

Silk Test does not support the Xpath function "count()". You can use can the "getChildren()" method to retrieve the element's children and then retrieve the size of the children list. Alternatively you can also use the "findAll()" method and retrieve the size of the returned list.

Example in Silk4J:

DomElement parent = browserApplication.find("//DIV[@class='title-section-conten*']");

System.out.println("number of direct children: " + parent.getChildren().size());

System.out.println("number of all decendants (children, grand children, etc): " + parent.findAll("//*").size());

0 Likes
garecanbp Contributor.
Contributor.

RE: Count Xpath

Jump to solution
could we use it in Silk Test Workbench?
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Count Xpath

Jump to solution

Yes should be able to do the same thing in Workbench .NET scripts and Visual test as well.

Example in a .NET script:

Dim numberOfDirectChildren = parent.GetChildren().Count

Dim numberOfDescendants = parent.FindAll("//*").Count

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.