I have a method to get an ancestor element of a web_element:
def find_ancestor(self, name):
element = self.driver.find_element_by_name(name)
ancestor = element.find_element_by_xpath("ancestor::*")
print(ancestor)
attr = ancestor.get_attribute("outerHTML")
print(attr)
The output for print(ancestor)
is <selenium.webdriver.remote.webelement.WebElement (session="43f99228044a37dab999a9512b5e268e", element="0.22129539497775563-3")>
When I try to access and print attributes I get an error: UnicodeEncodeError: 'charmap' codec can't encode character u'\xae' in position 292: character maps to <undefined>
The top of my script has # -*- coding: utf-8 -*
What am I missing/doing wrong? My feeling is 'ancestor' returns differently than other xpath axes!?
background/bonus help
Ideally, I want methods to get parent, preceding-sibling, following-sibling etc.
But when I try such actions on a table cell preceding-sibling
is not getting the previous cell (no element found), and with parent
I am getting back the same element (the same table cell and not table row).
I am showing python but don't mind answers in c#.