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

Method set_attribute

seleniumbase/fixtures/base_case.py:1977–2017  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

1975 return None
1976
1977 def set_attribute(
1978 self,
1979 selector,
1980 attribute,
1981 value,
1982 by="css selector",
1983 timeout=None,
1984 scroll=False,
1985 ):
1986 """This method uses JavaScript to set/update an attribute.
1987 Only the first matching selector from querySelector() is used."""
1988 self.__check_scope()
1989 if not timeout:
1990 timeout = settings.LARGE_TIMEOUT
1991 if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
1992 timeout = self.__get_new_timeout(timeout)
1993 selector, by = self.__recalculate_selector(selector, by)
1994 original_attribute = attribute
1995 original_value = value
1996 if scroll and self.is_element_visible(selector, by=by):
1997 with suppress(Exception):
1998 self.scroll_to(selector, by=by, timeout=timeout)
1999 attribute = re.escape(attribute)
2000 attribute = self.__escape_quotes_if_needed(attribute)
2001 value = re.escape(value)
2002 value = self.__escape_quotes_if_needed(value)
2003 css_selector = self.convert_to_css_selector(selector, by=by)
2004 css_selector = re.escape(css_selector) # Add "\\" to special chars
2005 css_selector = self.__escape_quotes_if_needed(css_selector)
2006 script = (
2007 """document.querySelector('%s').setAttribute('%s','%s');"""
2008 % (css_selector, attribute, value)
2009 )
2010 self.execute_script(script)
2011 if self.recorder_mode and self.__current_url_is_recordable():
2012 if self.get_session_storage_item("pause_recorder") == "no":
2013 time_stamp = self.execute_script("return Date.now();")
2014 origin = self.get_origin()
2015 sele_attr_val = [selector, original_attribute, original_value]
2016 action = ["s_at_", sele_attr_val, origin, time_stamp]
2017 self.__extra_actions.append(action)
2018
2019 def set_attributes(self, selector, attribute, value, by="css selector"):
2020 """This method uses JavaScript to set/update a common attribute.

Callers 14

set_attributeFunction · 0.80
attribuut_instellenMethod · 0.80
définir_attributMethod · 0.80
imposta_attributoMethod · 0.80
establecer_atributoMethod · 0.80
특성_설정Method · 0.80
属性を設定するMethod · 0.80
设置属性Method · 0.80
definir_atributoMethod · 0.80
test_hack_searchMethod · 0.80

Calls 11

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

Tested by 4

test_hack_searchMethod · 0.64
test_xkcd_logo_changeMethod · 0.64