Skip to content

Commit edf50ad

Browse files
committed
Added keyword 'Get WebElement'
1 parent d6a42af commit edf50ad

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Selenium2Library/keywords/_element.py

Lines changed: 9 additions & 2 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.get_webelements(locator)[0]
30+
2431
def get_webelements(self, locator):
2532
"""Returns list of WebElement objects matching locator.
2633
@@ -599,7 +606,7 @@ def get_matching_xpath_count(self, xpath):
599606
"""Returns number of elements matching `xpath`
600607
601608
One should not use the xpath= prefix for 'xpath'. XPath is assumed.
602-
609+
603610
Correct:
604611
| count = | Get Matching Xpath Count | //div[@id='sales-pop']
605612
Incorrect:
@@ -615,7 +622,7 @@ def xpath_should_match_x_times(self, xpath, expected_xpath_count, message='', lo
615622
"""Verifies that the page contains the given number of elements located by the given `xpath`.
616623
617624
One should not use the xpath= prefix for 'xpath'. XPath is assumed.
618-
625+
619626
Correct:
620627
| Xpath Should Match X Times | //div[@id='sales-pop'] | 1
621628
Incorrect:

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 First Matching Element
11+
@{links}= Get WebElements //div[@id="div_id"]/a
12+
${link}= Get WebElement //div[@id="div_id"]/a
13+
LOG @{links}[0]
14+
LOG ${link}
15+
Should Be Equal @{links}[0] ${link}
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)