diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 9991961b3..3a461a74f 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -622,9 +622,12 @@ def page_should_not_contain_image(self, locator, message='', loglevel='INFO'): # Public, xpath - def get_matching_xpath_count(self, xpath): + def get_matching_xpath_count(self, xpath, return_str=True): """Returns number of elements matching `xpath` + The default return type is `str` but it can changed to `int` by setting + the ``return_str`` argument to Python False. + One should not use the xpath= prefix for 'xpath'. XPath is assumed. Correct: @@ -636,7 +639,7 @@ def get_matching_xpath_count(self, xpath): `Xpath Should Match X Times`. """ count = len(self._element_find("xpath=" + xpath, False, False)) - return str(count) + return str(count) if return_str else count def xpath_should_match_x_times(self, xpath, expected_xpath_count, message='', loglevel='INFO'): """Verifies that the page contains the given number of elements located by the given `xpath`. diff --git a/test/acceptance/keywords/elements.robot b/test/acceptance/keywords/elements.robot index 4210418f2..47e9de174 100644 --- a/test/acceptance/keywords/elements.robot +++ b/test/acceptance/keywords/elements.robot @@ -2,6 +2,7 @@ Documentation Tests elements Test Setup Go To Page "links.html" Resource ../resource.robot +Library String *** Test Cases *** Get Elements @@ -61,6 +62,12 @@ Get Matching XPath Count [Documentation] Get Matching XPath Count ${count}= Get Matching XPath Count //a Should Be Equal ${count} 19 + ${count}= Get Matching XPath Count //a ${True} + Should Be Equal ${count} 19 + Should Be String ${count} + ${count}= Get Matching XPath Count //a ${False} + Should Be Equal ${count} ${19} + Should Not Be String ${count} ${count}= Get Matching XPath Count //div[@id="first_div"]/a Should Be Equal ${count} 2