Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/Selenium2Library/keywords/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion test/acceptance/keywords/elements.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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