Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ehdud8451 opened this issue Jun 12, 2025 · 1 comment · Fixed by #3815
Closed

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

ehdud8451 opened this issue Jun 12, 2025 · 1 comment · Fixed by #3815
Assignees
Labels
bug Uh oh... Something needs to be fixed UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@ehdud8451
Copy link

# 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
@mdmintz mdmintz added bug Uh oh... Something needs to be fixed UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Jun 12, 2025
@mdmintz mdmintz self-assigned this Jun 12, 2025
@mdmintz
Copy link
Member

mdmintz commented Jun 12, 2025

This was resolved in 4.39.4 - https://github.com/seleniumbase/SeleniumBase/releases/tag/v4.39.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh oh... Something needs to be fixed UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants