When using Fitnesse, Slim and the Browser Testing framework I was given the challenge to count the amount of items within an ordered list (simplified):


I found that one of the counting methods:

|check |number of items |xpath=//b |in |xpath=//a |3 |

does not work since it would only test for the number of times text appears upon a webpage, not the element. Thus I was pointed to the counting function of xpath but that returns the list of items instead of the total amount of occurrences, as seen below:

|check |value of        |xpath=//ol[count(li)=3] |[<b>1</b>
                                                   <b>3</b>] expected: [3] |

As such, how would I be able to get an integer of the count of occurrences of a certain element?

1 Answers

supputuri On

You have to wrap the entire xpath with count as shown below.

Considered ol with `class="nav-links" for the below explanation.


Checking the number of li under the above said ol in chrome Elements tab.

Note: you don't get any output if you try count(xpath) in Elements tab. Count from Chrome Elements Tab

To see the count just tested the xpath in the chrome Console tab. Count from Chrome Elements Tab