Hide the first element on the page that matches the selector.
(self, selector, by="css selector")
| 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.""" |
nothing calls this directly
no test coverage detected