Skip to content

Commit

Permalink
py: make it possible to specialise web element
Browse files Browse the repository at this point in the history
This patch makes it possible for individual drivers to
provide specialised WebElement classes through overriding
selenium.webdriver.remote.webelement.WebElement
and defining the _web_element_cls property on
selenium.webdriver.remote.webdriver.WebDriver.

This would enable client bindings for a particular browser to provide
custom methods also on the web element level.  Currently vendor extension
commands are only possible on the WebDriver level.
  • Loading branch information
andreastt committed Aug 31, 2016
1 parent e867146 commit 09dab5a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class WebDriver(object):
- error_handler - errorhandler.ErrorHandler object used to handle errors.
"""

_web_element_cls = WebElement

def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=None, browser_profile=None, proxy=None,
keep_alive=False, file_detector=None):
Expand Down Expand Up @@ -187,18 +189,16 @@ def _wrap_value(self, value):
for key, val in value.items():
converted[key] = self._wrap_value(val)
return converted
elif isinstance(value, WebElement):
elif isinstance(value, self._web_element_cls):
return {'ELEMENT': value.id, 'element-6066-11e4-a52e-4f735466cecf': value.id}
elif isinstance(value, list):
return list(self._wrap_value(item) for item in value)
else:
return value

def create_web_element(self, element_id):
"""
Creates a web element with the specified element_id.
"""
return WebElement(self, element_id, w3c=self.w3c)
"""Creates a web element with the specified `element_id`."""
return self._web_element_cls(self, element_id, w3c=self.w3c)

def _unwrap_value(self, value):
if isinstance(value, dict) and ('ELEMENT' in value or 'element-6066-11e4-a52e-4f735466cecf' in value):
Expand Down

0 comments on commit 09dab5a

Please sign in to comment.