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

Method update_text

seleniumbase/fixtures/base_case.py:888–1015  ·  view source on GitHub ↗

This method updates an element's text field with new text. Has multiple parts: * Waits for the element to be visible. * Waits for the element to be interactive. * Clears the text field. * Types in the new text. * Hits Enter/Submit (if the text ends in

(
        self, selector, text, by="css selector", timeout=None, retry=False
    )

Source from the content-addressed store, hash-verified

886 time.sleep(spacing)
887
888 def update_text(
889 self, selector, text, by="css selector", timeout=None, retry=False
890 ):
891 """This method updates an element's text field with new text.
892 Has multiple parts:
893 * Waits for the element to be visible.
894 * Waits for the element to be interactive.
895 * Clears the text field.
896 * Types in the new text.
897 * Hits Enter/Submit (if the text ends in "\n").
898 @Params
899 selector - The selector of the text field.
900 text - The new text to type into the text field.
901 by - The type of selector to search by. (Default: "css selector")
902 timeout - How long to wait for the selector to be visible.
903 retry - If True, use JS if the Selenium text update fails."""
904 self.__check_scope()
905 if not timeout:
906 timeout = settings.LARGE_TIMEOUT
907 if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
908 timeout = self.__get_new_timeout(timeout)
909 selector, by = self.__recalculate_selector(selector, by)
910 if self.__is_cdp_swap_needed():
911 self.cdp.type(selector, text, timeout=timeout)
912 return
913 if self.__is_shadow_selector(selector):
914 self.__shadow_type(selector, text, timeout)
915 return
916 element = self.wait_for_element_clickable(
917 selector, by=by, timeout=timeout
918 )
919 self.__demo_mode_highlight_if_active(selector, by)
920 if not self.demo_mode and not self.slow_mode:
921 self.__scroll_to_element(element, selector, by)
922 if self.__needs_minimum_wait():
923 time.sleep(0.04)
924 try:
925 element.clear() # May need https://stackoverflow.com/a/50691625
926 backspaces = Keys.BACK_SPACE * 42 # Is the answer to everything
927 element.send_keys(backspaces) # In case autocomplete keeps text
928 except (Stale_Exception, ENI_Exception):
929 self.wait_for_ready_state_complete()
930 time.sleep(0.16)
931 element = self.wait_for_element_clickable(
932 selector, by=by, timeout=timeout
933 )
934 with suppress(Exception):
935 element.clear()
936 except Exception:
937 pass # Clearing the text field first might not be necessary
938 self.__demo_mode_pause_if_active(tiny=True)
939 pre_action_url = None
940 if self.demo_mode:
941 with suppress(Exception):
942 pre_action_url = self.driver.current_url
943 text = self.__get_type_checked_text(text)
944 try:
945 if not text.endswith("\n"):

Callers 15

typeMethod · 0.95
highlight_update_textMethod · 0.95
highlight_typeMethod · 0.95
enter_mfa_codeMethod · 0.95
inputMethod · 0.95
fillMethod · 0.95
writeMethod · 0.95
tekst_bijwerkenMethod · 0.45
modifier_texteMethod · 0.45
aggiornare_testoMethod · 0.45
actualizar_textoMethod · 0.45

Calls 15

__check_scopeMethod · 0.95
__get_new_timeoutMethod · 0.95
__is_cdp_swap_neededMethod · 0.95
__is_shadow_selectorMethod · 0.95
__shadow_typeMethod · 0.95
__scroll_to_elementMethod · 0.95
__needs_minimum_waitMethod · 0.95

Tested by

no test coverage detected