MCPcopy Index your code
hub / github.com/seleniumbase/SeleniumBase / get_attribute

Method get_attribute

seleniumbase/fixtures/base_case.py:1926–1975  ·  view source on GitHub ↗

This method uses JavaScript to get the value of an attribute. If the attribute doesn't exist or isn't found, an exception will get raised if hard_fail is True (otherwise None is returned).

(
        self,
        selector,
        attribute,
        by="css selector",
        timeout=None,
        hard_fail=True,
    )

Source from the content-addressed store, hash-verified

1924 return element_text
1925
1926 def get_attribute(
1927 self,
1928 selector,
1929 attribute,
1930 by="css selector",
1931 timeout=None,
1932 hard_fail=True,
1933 ):
1934 """This method uses JavaScript to get the value of an attribute.
1935 If the attribute doesn't exist or isn't found, an exception will
1936 get raised if hard_fail is True (otherwise None is returned)."""
1937 self.__check_scope()
1938 if not timeout:
1939 timeout = settings.LARGE_TIMEOUT
1940 if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
1941 timeout = self.__get_new_timeout(timeout)
1942 selector, by = self.__recalculate_selector(selector, by)
1943 if self.__is_cdp_swap_needed():
1944 if hard_fail:
1945 return self.cdp.get_element_attribute(selector, attribute)
1946 else:
1947 return self.cdp.get_attribute(selector, attribute)
1948 self.wait_for_ready_state_complete()
1949 time.sleep(0.01)
1950 if self.__is_shadow_selector(selector):
1951 return self.__get_shadow_attribute(
1952 selector, attribute, timeout=timeout
1953 )
1954 element = page_actions.wait_for_element_present(
1955 self.driver, selector, by, timeout
1956 )
1957 try:
1958 attribute_value = element.get_attribute(attribute)
1959 except (Stale_Exception, ENI_Exception, TimeoutException):
1960 self.wait_for_ready_state_complete()
1961 time.sleep(0.14)
1962 element = page_actions.wait_for_element_present(
1963 self.driver, selector, by, timeout
1964 )
1965 attribute_value = element.get_attribute(attribute)
1966 if attribute_value is not None:
1967 return attribute_value
1968 else:
1969 if hard_fail:
1970 raise Exception(
1971 "Element {%s} has no attribute {%s}!"
1972 % (selector, attribute)
1973 )
1974 else:
1975 return None
1976
1977 def set_attribute(
1978 self,

Callers 15

get_image_urlMethod · 0.95
is_checkedMethod · 0.95
clickMethod · 0.45
update_textMethod · 0.45
get_textMethod · 0.45
__element_clickMethod · 0.45
get_select_optionsMethod · 0.45
__highlight_elementMethod · 0.45
__highlightMethod · 0.45
__get_shadow_textMethod · 0.45

Calls 10

__check_scopeMethod · 0.95
__get_new_timeoutMethod · 0.95
__is_cdp_swap_neededMethod · 0.95
__is_shadow_selectorMethod · 0.95
get_element_attributeMethod · 0.80
sleepMethod · 0.45

Tested by

no test coverage detected