MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / remove_attribute

Method remove_attribute

seleniumbase/fixtures/base_case.py:2064–2087  ·  view source on GitHub ↗

This method uses JavaScript to remove an attribute. Only the first matching selector from querySelector() is used.

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

Source from the content-addressed store, hash-verified

2062 self.set_attributes(selector, attribute, value, by=by)
2063
2064 def remove_attribute(
2065 self, selector, attribute, by="css selector", timeout=None
2066 ):
2067 """This method uses JavaScript to remove an attribute.
2068 Only the first matching selector from querySelector() is used."""
2069 self.__check_scope()
2070 if not timeout:
2071 timeout = settings.LARGE_TIMEOUT
2072 if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
2073 timeout = self.__get_new_timeout(timeout)
2074 selector, by = self.__recalculate_selector(selector, by)
2075 if self.is_element_visible(selector, by=by):
2076 with suppress(Exception):
2077 self.scroll_to(selector, by=by, timeout=timeout)
2078 attribute = re.escape(attribute)
2079 attribute = self.__escape_quotes_if_needed(attribute)
2080 css_selector = self.convert_to_css_selector(selector, by=by)
2081 css_selector = re.escape(css_selector) # Add "\\" to special chars
2082 css_selector = self.__escape_quotes_if_needed(css_selector)
2083 script = """document.querySelector('%s').removeAttribute('%s');""" % (
2084 css_selector,
2085 attribute,
2086 )
2087 self.execute_script(script)
2088
2089 def remove_attributes(self, selector, attribute, by="css selector"):
2090 """This method uses JavaScript to remove a common attribute.

Callers

nothing calls this directly

Calls 8

__check_scopeMethod · 0.95
__get_new_timeoutMethod · 0.95
is_element_visibleMethod · 0.95
scroll_toMethod · 0.95
execute_scriptMethod · 0.95

Tested by

no test coverage detected