Skip to content

Commit 465610b

Browse files
committed
Merge pull request #473 from rtomac/get-webelement
Added keyword 'Get WebElement'
2 parents d11f6a4 + d9f72ef commit 465610b

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Release Notes
22
=============
33

4+
1.7.3 (unreleased)
5+
-------------------
6+
- Added 'Get WebElement' [zephraph][emanlove]
7+
48
1.7.2
59
----------------
610
- Added an argument called screenshot_root_directory that can be passed into S2L's

src/Selenium2Library/keywords/_element.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ def __init__(self):
2121

2222
# Public, get element(s)
2323

24+
def get_webelement(self, locator):
25+
"""Returns the first WebElement matching the given locator.
26+
27+
See `introduction` for details about locating elements.
28+
"""
29+
return self._element_find(locator, True, True)
30+
2431
def get_webelements(self, locator):
2532
"""Returns list of WebElement objects matching locator.
2633

test/acceptance/keywords/elements.robot

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Get Elements
77
@{links}= Get WebElements //div[@id="div_id"]/a
88
Length Should Be ${links} 11
99

10+
Get Web Element
11+
@{links}= Get WebElements //div[@id="div_id"]/a
12+
${link}= Get WebElement //div[@id="div_id"]/a
13+
Should Be Equal @{links}[0] ${link}
14+
Run Keyword and Expect Error ValueError: Element locator 'id=non_existing_elem' did not match any elements.
15+
... Get WebElement id=non_existing_elem
16+
1017
More Get Elements
1118
[Setup] Go To Page "forms/prefilled_email_form.html"
1219
@{checkboxes}= Get WebElements //input[@type="checkbox"]
@@ -51,4 +58,3 @@ Get Vertical Position
5158
${pos}= Get Vertical Position link=Link
5259
Should Be True ${pos} > ${0}
5360
Run Keyword And Expect Error Could not determine position for 'non-existent' Get Horizontal Position non-existent
54-

0 commit comments

Comments
 (0)