Skip to content

Commit e061272

Browse files
committed
Merge pull request robotframework#528 from SergiuTudos/master
Get Element Size.
2 parents 2685fc7 + 8930563 commit e061272

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/Selenium2Library/keywords/_element.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,16 @@ def get_horizontal_position(self, locator):
297297
raise AssertionError("Could not determine position for '%s'" % (locator))
298298
return element.location['x']
299299

300+
def get_element_size(self, locator):
301+
"""Returns width and height of element identified by `locator`.
302+
303+
The element width and height is returned.
304+
Fails if a matching element is not found.
305+
"""
306+
element = self._element_find(locator, True, True)
307+
308+
return element.size['width'], element.size['height']
309+
300310
def get_value(self, locator):
301311
"""Returns the value attribute of element identified by `locator`.
302312

test/acceptance/keywords/elements.robot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@ Get Vertical Position
6969
Should Be True ${pos} > ${0}
7070
Run Keyword And Expect Error Could not determine position for 'non-existent'
7171
... Get Horizontal Position non-existent
72+
73+
74+
Get Element Size
75+
${width} ${height}= Get Element Size link=Link
76+
Should be True ${height} > ${0}
77+
Should be True ${width} > ${0}
78+
Run Keyword And Expect Error ValueError: Element locator 'non-existent' did not match any elements. Get Element Size non-existent
79+
80+
Get Empty Element Size
81+
${width} ${height}= Get Element Size id=emptyDiv
82+
Should be True ${height} == 0

test/resources/html/links.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<a href="target/second.html"><img src="robot.png" alt="Image"/></a>
3636
<a href="target/second.html">Link</a>
3737
</div>
38+
<div id="emptyDiv"></div>
3839
<a href="index.html" target="_blank">Target opens in new window</a>
3940
</body>
4041
</html>

0 commit comments

Comments
 (0)