Closed
Description
# sb.get_attribute
def get_attribute(
self,
selector,
attribute,
by="css selector",
timeout=None,
hard_fail=True,
):
~~~~~
if self.__is_cdp_swap_needed():
return self.cdp.get_element_attribute(selector, attribute)
~~~~~
if attribute_value is not None:
return attribute_value
else:
if hard_fail:
raise Exception(
"Element {%s} has no attribute {%s}!"
% (selector, attribute)
)
else:
return None
# cdp.get_element_attribute
def get_element_attribute(self, selector, attribute):
attributes = self.get_element_attributes(selector)
with suppress(Exception):
return attributes[attribute]
locate = ' %s="' % attribute
value = self.get_attribute(selector, attribute)
if not value and locate not in attributes:
# >>> RAISE EXCEPTION HERE <<<
raise KeyError(attribute)
return value