Skip to content

Commit 6184e07

Browse files
committed
Add jquery_type(selector, text)
1 parent 6040463 commit 6184e07

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

help_docs/method_summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ self.js_update_text(selector, text, by="css selector", timeout=None)
514514
self.set_text_content(selector, text, by="css selector", timeout=None, scroll=False)
515515

516516
self.jquery_update_text(selector, text, by="css selector", timeout=None)
517+
# Duplicates: self.jquery_type(selector, text, by="css selector", timeout=None)
517518

518519
self.get_value(selector, by="css selector", timeout=None)
519520

seleniumbase/fixtures/base_case.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7439,16 +7439,48 @@ def jquery_update_text(
74397439
self.__demo_mode_highlight_if_active(selector, by)
74407440
self.scroll_to(selector, by=by)
74417441
selector = self.convert_to_css_selector(selector, by=by)
7442+
css_selector = selector
74427443
selector = self.__make_css_match_first_element_only(selector)
74437444
selector = self.__escape_quotes_if_needed(selector)
74447445
text = re.escape(text)
74457446
text = self.__escape_quotes_if_needed(text)
74467447
update_text_script = """jQuery('%s').val('%s');""" % (selector, text)
7448+
if self.recorder_mode and self.__current_url_is_recordable():
7449+
if self.get_session_storage_item("pause_recorder") == "no":
7450+
time_stamp = self.execute_script("return Date.now();")
7451+
origin = self.get_origin()
7452+
sel_tex = [css_selector, text]
7453+
action = ["jq_ty", sel_tex, origin, time_stamp]
7454+
self.__extra_actions.append(action)
74477455
self.safe_execute_script(update_text_script)
74487456
if text.endswith("\n"):
7449-
element.send_keys("\n")
7457+
element = self.wait_for_element_present(
7458+
original_selector, by=original_by, timeout=0.2
7459+
)
7460+
element.send_keys(Keys.RETURN)
7461+
else:
7462+
try:
7463+
element = self.wait_for_element_present(
7464+
original_selector, by=original_by, timeout=0.2
7465+
)
7466+
element.send_keys(" " + Keys.BACK_SPACE)
7467+
except Exception:
7468+
pass
74507469
self.__demo_mode_pause_if_active()
74517470

7471+
def jquery_type(self, selector, text, by="css selector", timeout=None):
7472+
"""Same as self.jquery_update_text()
7473+
JQuery is used to update a text field.
7474+
Performs jQuery(selector).val(text); and triggers event listeners.
7475+
If text ends in "\n", presses RETURN after."""
7476+
self.__check_scope()
7477+
if not timeout:
7478+
timeout = settings.LARGE_TIMEOUT
7479+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
7480+
timeout = self.__get_new_timeout(timeout)
7481+
selector, by = self.__recalculate_selector(selector, by)
7482+
self.jquery_update_text(selector, text, by=by, timeout=timeout)
7483+
74527484
def get_value(self, selector, by="css selector", timeout=None):
74537485
"""This method uses JavaScript to get the value of an input field.
74547486
(Works on both input fields and textarea fields.)"""

0 commit comments

Comments
 (0)