Extending WebElement methods

Has anyone had success extending WebElement objects? I’m specifically using Python and have followed this StackOverflow answer but I’m unable to access my new method using<WebElementObject>.<newly_added_method>().

On inspection, I can see that _web_element_cls is set on the parent driver but it doesn’t seem like the created WebElement is using my subclass.

Any experience with this? In any language?

Ah - I was able to find a way… I needed to overide the create_web_element method within my custom WebDriver class… once I did this, all new web elements created had my extension methods.

1 Like