Skip to content

Commit 09dab5a

Browse files
committed
py: make it possible to specialise web element
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.
1 parent e867146 commit 09dab5a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

py/selenium/webdriver/remote/webdriver.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class WebDriver(object):
5353
- error_handler - errorhandler.ErrorHandler object used to handle errors.
5454
"""
5555

56+
_web_element_cls = WebElement
57+
5658
def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
5759
desired_capabilities=None, browser_profile=None, proxy=None,
5860
keep_alive=False, file_detector=None):
@@ -187,18 +189,16 @@ def _wrap_value(self, value):
187189
for key, val in value.items():
188190
converted[key] = self._wrap_value(val)
189191
return converted
190-
elif isinstance(value, WebElement):
192+
elif isinstance(value, self._web_element_cls):
191193
return {'ELEMENT': value.id, 'element-6066-11e4-a52e-4f735466cecf': value.id}
192194
elif isinstance(value, list):
193195
return list(self._wrap_value(item) for item in value)
194196
else:
195197
return value
196198

197199
def create_web_element(self, element_id):
198-
"""
199-
Creates a web element with the specified element_id.
200-
"""
201-
return WebElement(self, element_id, w3c=self.w3c)
200+
"""Creates a web element with the specified `element_id`."""
201+
return self._web_element_cls(self, element_id, w3c=self.w3c)
202202

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

0 commit comments

Comments
 (0)