Skip to content

Commit cd218d0

Browse files
[Py] Update webelement to handle W3C commands for size/location and rect
1 parent c489f7c commit cd218d0

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

py/selenium/webdriver/remote/webelement.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,13 @@ def location_once_scrolled_into_view(self):
353353
@property
354354
def size(self):
355355
"""The size of the element."""
356-
size = self._execute(Command.GET_ELEMENT_SIZE)['value']
357-
new_size = {}
358-
new_size["height"] = size["height"]
359-
new_size["width"] = size["width"]
356+
size = {}
357+
if self._w3c:
358+
size = self._execute(Command.GET_ELEMENT_RECT)
359+
else:
360+
size = self._execute(Command.GET_ELEMENT_SIZE)['value']
361+
new_size = {"height": size["height"],
362+
"width": size["width"]}
360363
return new_size
361364

362365
def value_of_css_property(self, property_name):
@@ -367,15 +370,21 @@ def value_of_css_property(self, property_name):
367370
@property
368371
def location(self):
369372
"""The location of the element in the renderable canvas."""
370-
old_loc = self._execute(Command.GET_ELEMENT_LOCATION)['value']
373+
if self._w3c:
374+
old_loc = self._execute(Command.GET_ELEMENT_RECT)
375+
else:
376+
old_loc = self._execute(Command.GET_ELEMENT_LOCATION)['value']
371377
new_loc = {"x": old_loc['x'],
372378
"y": old_loc['y']}
373379
return new_loc
374380

375381
@property
376382
def rect(self):
377383
"""A dictionary with the size and location of the element."""
378-
return self._execute(Command.GET_ELEMENT_RECT)['value']
384+
if self._w3c:
385+
return self._execute(Command.GET_ELEMENT_RECT)
386+
else:
387+
return self._execute(Command.GET_ELEMENT_RECT)['value']
379388

380389
@property
381390
def screenshot_as_base64(self):

0 commit comments

Comments
 (0)