Skip to content

Commit c348288

Browse files
committed
Add "self.set_text(SELECTOR, TEXT)"
1 parent c5ec5fb commit c348288

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

help_docs/method_summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ self.set_value(selector, text, by=By.CSS_SELECTOR, timeout=None)
321321

322322
self.js_update_text(selector, text, by=By.CSS_SELECTOR, timeout=None)
323323
# Duplicates: self.js_type(selector, text, by=By.CSS_SELECTOR, timeout=None)
324+
# self.set_text(selector, text, by=By.CSS_SELECTOR, timeout=None)
324325

325326
self.jquery_update_text(selector, text, by=By.CSS_SELECTOR, timeout=None)
326327

seleniumbase/fixtures/base_case.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,6 +3155,29 @@ def js_type(self, selector, text, by=By.CSS_SELECTOR,
31553155
except Exception:
31563156
pass
31573157

3158+
def set_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
3159+
""" Same as self.js_update_text()
3160+
JavaScript + send_keys are used to update a text field.
3161+
Performs self.set_value() and triggers event listeners.
3162+
If text ends in "\n", set_value() presses RETURN after.
3163+
Works faster than send_keys() alone due to the JS call. """
3164+
if not timeout:
3165+
timeout = settings.LARGE_TIMEOUT
3166+
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
3167+
timeout = self.__get_new_timeout(timeout)
3168+
selector, by = self.__recalculate_selector(selector, by)
3169+
if type(text) is int or type(text) is float:
3170+
text = str(text)
3171+
self.set_value(
3172+
selector, text, by=by, timeout=timeout)
3173+
if not text.endswith('\n'):
3174+
try:
3175+
element = page_actions.wait_for_element_present(
3176+
self.driver, selector, by, timeout=0.2)
3177+
element.send_keys(" \b")
3178+
except Exception:
3179+
pass
3180+
31583181
def jquery_update_text(self, selector, text, by=By.CSS_SELECTOR,
31593182
timeout=None):
31603183
""" This method uses jQuery to update a text field.

0 commit comments

Comments
 (0)