Count Xpath

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?

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

  • In reply to michaelg:

    could we use it in Silk Test Workbench?
  • In reply to garecanbp:

    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