Skip to content

In CDP mode, the hard_fail parameter is ignored when use get_attribute function. #3813

Closed
@ehdud8451

Description

@ehdud8451
# 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

Metadata

Metadata

Assignees

Labels

UC Mode / CDP ModeUndetected Chromedriver Mode / CDP ModebugUh oh... Something needs to be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions