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

Method hide_element

seleniumbase/fixtures/base_case.py:7301–7330  ·  view source on GitHub ↗

Hide the first element on the page that matches the selector.

(self, selector, by="css selector")

Source from the content-addressed store, hash-verified

7299 self.__demo_mode_pause_if_active()
7300
7301 def hide_element(self, selector, by="css selector"):
7302 """Hide the first element on the page that matches the selector."""
7303 self.__check_scope()
7304 element = None
7305 with suppress(Exception):
7306 self.wait_for_element_visible("body", timeout=1.5)
7307 element = self.wait_for_element_present(
7308 selector, by=by, timeout=0.5
7309 )
7310 selector, by = self.__recalculate_selector(selector, by)
7311 css_selector = self.convert_to_css_selector(selector, by=by)
7312 if ":contains(" in css_selector and element:
7313 script = (
7314 'const e = arguments[0];'
7315 'e.style.display="none";e.style.visibility="hidden";'
7316 )
7317 self.execute_script(script, element)
7318 elif ":contains(" in css_selector and not element:
7319 selector = self.__make_css_match_first_element_only(css_selector)
7320 script = """jQuery('%s').hide();""" % selector
7321 self.safe_execute_script(script)
7322 else:
7323 css_selector = re.escape(css_selector) # Add "\\" to special chars
7324 css_selector = self.__escape_quotes_if_needed(css_selector)
7325 script = (
7326 'const e = document.querySelector("%s");'
7327 'e.style.display="none";e.style.visibility="hidden";'
7328 % css_selector
7329 )
7330 self.execute_script(script)
7331
7332 def hide_elements(self, selector, by="css selector"):
7333 """Hide all elements on the page that match the selector."""

Callers

nothing calls this directly

Calls 9

__check_scopeMethod · 0.95
execute_scriptMethod · 0.95
safe_execute_scriptMethod · 0.95

Tested by

no test coverage detected