diff --git a/CHANGES.rst b/CHANGES.rst index e5fa6931d..3df9ee3dc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,10 @@ Release Notes ============= +1.7.3 (unreleased) +------------------- +- Added 'Get WebElement' [zephraph][emanlove] + 1.7.2 ---------------- - Added an argument called screenshot_root_directory that can be passed into S2L's diff --git a/src/Selenium2Library/keywords/_element.py b/src/Selenium2Library/keywords/_element.py index 5a2cf7470..655782a55 100644 --- a/src/Selenium2Library/keywords/_element.py +++ b/src/Selenium2Library/keywords/_element.py @@ -21,6 +21,13 @@ def __init__(self): # Public, get element(s) + def get_webelement(self, locator): + """Returns the first WebElement matching the given locator. + + See `introduction` for details about locating elements. + """ + return self._element_find(locator, True, True) + def get_webelements(self, locator): """Returns list of WebElement objects matching locator. @@ -599,7 +606,7 @@ def get_matching_xpath_count(self, xpath): """Returns number of elements matching `xpath` One should not use the xpath= prefix for 'xpath'. XPath is assumed. - + Correct: | count = | Get Matching Xpath Count | //div[@id='sales-pop'] Incorrect: @@ -615,7 +622,7 @@ def xpath_should_match_x_times(self, xpath, expected_xpath_count, message='', lo """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: diff --git a/test/acceptance/keywords/elements.robot b/test/acceptance/keywords/elements.robot index 4e7c731f1..21706ce0a 100644 --- a/test/acceptance/keywords/elements.robot +++ b/test/acceptance/keywords/elements.robot @@ -7,6 +7,13 @@ Get Elements @{links}= Get WebElements //div[@id="div_id"]/a Length Should Be ${links} 11 +Get Web Element + @{links}= Get WebElements //div[@id="div_id"]/a + ${link}= Get WebElement //div[@id="div_id"]/a + Should Be Equal @{links}[0] ${link} + Run Keyword and Expect Error ValueError: Element locator 'id=non_existing_elem' did not match any elements. + ... Get WebElement id=non_existing_elem + More Get Elements [Setup] Go To Page "forms/prefilled_email_form.html" @{checkboxes}= Get WebElements //input[@type="checkbox"] @@ -51,4 +58,3 @@ Get Vertical Position ${pos}= Get Vertical Position link=Link Should Be True ${pos} > ${0} Run Keyword And Expect Error Could not determine position for 'non-existent' Get Horizontal Position non-existent -