0

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

<a>
    <b>1</b>
    <b>2</b>
    <b>3</b>
</a>

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>2</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?

eymas
  • 105
  • 2
  • 15

1 Answers1

0

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

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

count(//ol[@class='nav-links']/li)

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

supputuri
  • 13,644
  • 2
  • 21
  • 39