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

Method jquery_update_text

seleniumbase/fixtures/base_case.py:9283–9330  ·  view source on GitHub ↗

This method uses jQuery to update a text field. If the text string ends with the newline character, Selenium finishes the call, which simulates pressing {Enter/Return} after the text is entered. This method also triggers event listeners.

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

Source from the content-addressed store, hash-verified

9281 self.__demo_mode_pause_if_active()
9282
9283 def jquery_update_text(
9284 self, selector, text, by="css selector", timeout=None
9285 ):
9286 """This method uses jQuery to update a text field.
9287 If the text string ends with the newline character,
9288 Selenium finishes the call, which simulates pressing
9289 {Enter/Return} after the text is entered.
9290 This method also triggers event listeners."""
9291 self.__check_scope()
9292 original_selector = selector
9293 original_by = by
9294 if not timeout:
9295 timeout = settings.LARGE_TIMEOUT
9296 if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
9297 timeout = self.__get_new_timeout(timeout)
9298 selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
9299 element = self.wait_for_element_visible(
9300 selector, by=by, timeout=timeout
9301 )
9302 self.__demo_mode_highlight_if_active(selector, by)
9303 self.scroll_to(selector, by=by)
9304 selector = self.convert_to_css_selector(selector, by=by)
9305 css_selector = selector
9306 selector = self.__make_css_match_first_element_only(selector)
9307 selector = self.__escape_quotes_if_needed(selector)
9308 text = re.escape(text)
9309 text = self.__escape_quotes_if_needed(text)
9310 update_text_script = """jQuery('%s').val('%s');""" % (selector, text)
9311 if self.recorder_mode and self.__current_url_is_recordable():
9312 if self.get_session_storage_item("pause_recorder") == "no":
9313 time_stamp = self.execute_script("return Date.now();")
9314 origin = self.get_origin()
9315 sel_tex = [css_selector, text]
9316 action = ["jq_ty", sel_tex, origin, time_stamp]
9317 self.__extra_actions.append(action)
9318 self.safe_execute_script(update_text_script)
9319 if text.endswith("\n"):
9320 element = self.wait_for_element_present(
9321 original_selector, by=original_by, timeout=0.2
9322 )
9323 element.send_keys(Keys.RETURN)
9324 else:
9325 with suppress(Exception):
9326 element = self.wait_for_element_present(
9327 original_selector, by=original_by, timeout=0.2
9328 )
9329 element.send_keys(" " + Keys.BACK_SPACE)
9330 self.__demo_mode_pause_if_active()
9331
9332 def jquery_type(self, selector, text, by="css selector", timeout=None):
9333 """Same as self.jquery_update_text()

Calls 15

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

Tested by

no test coverage detected