I have an object element
that is returned by another class method I don't necessarily have access to change.
>>> from selenium.webdriver import Chrome
>>> browser = Chrome()
>>> browser.get('https://www.google.com')
>>> element = driver.find_element_by_tag_name('input')
>>> type(element)
<class 'selenium.webdriver.remote.webelement.WebElement'>
I have a separate class that extends the functionality of the element.
>>> class Input:
>>> def __init__(self, element):
>>> assert element.tag_name == 'input', 'Element must be of type "input"'
>>> self.element = element
>>> self.browser = element.parent
>>> def is_enabled(self):
>>> return self.element.is_enabled()
>>> @property
>>> def value(self):
>>> return self.element.get_attribute('value')
Currently the way I use this is by passing element
into the class:
>>> input = Input(element)
>>> input.is_enabled() # Same as input.element.is_enabled()
True
I want to be able to more easily access the original object's attributes rather than having to specify it in the call. For example:
Instead of this:
>>> input.element.tag_name
'input'
Do this:
>>> input.tag_name
'input'
How would I implement something like this?
element
.