'Verifies that the page contains the given number of elements located by the given `xpath`.
One should not use the xpath= prefix for \'xpath\'. XPath is assumed.
Correct:
| Xpath Should Match X Times | //div[@id=\'sales-pop\'] | 1
Incorrect:
| Xpath Should Match X Times | xpath=//div[@id=\'sales-pop\'] | 1
See `Page Should Contain Element` for explanation about `message` and
`loglevel` arguments.'

@keyword
def xpath_should_match_x_times(self, xpath, expected_xpath_count, message='', loglevel='INFO'):

    actual_xpath_count = len(self.find_element(('xpath=' + xpath), first_only=False, required=False))
    if (int(actual_xpath_count) != int(expected_xpath_count)):
        if (not message):
            message = ('Xpath    %s    should    have    matched    %s    times    but    matched    %s    times' % (xpath, expected_xpath_count, actual_xpath_count))
        self.ctx.log_source(loglevel)
        raise AssertionError(message)
    self.info(("Current    page    contains    %s    elements    matching    '%s'." % (actual_xpath_count, xpath)))
