Skip to content

Commit 90d5df0

Browse files
committed
Update parameter names and add methods
1 parent b1db6cc commit 90d5df0

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def get_image_url(self, selector, by=By.CSS_SELECTOR,
543543
return self.get_attribute(selector,
544544
attribute='src', by=by, timeout=timeout)
545545

546-
def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
546+
def add_text(self, selector, text, by=By.CSS_SELECTOR,
547547
timeout=settings.LARGE_TIMEOUT):
548548
""" The more-reliable version of driver.send_keys()
549549
Similar to update_text(), but won't clear the text field first. """
@@ -558,11 +558,11 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
558558
self.__scroll_to_element(element)
559559
pre_action_url = self.driver.current_url
560560
try:
561-
if not new_value.endswith('\n'):
562-
element.send_keys(new_value)
561+
if not text.endswith('\n'):
562+
element.send_keys(text)
563563
else:
564-
new_value = new_value[:-1]
565-
element.send_keys(new_value)
564+
text = text[:-1]
565+
element.send_keys(text)
566566
element.send_keys(Keys.RETURN)
567567
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
568568
self.wait_for_ready_state_complete()
@@ -571,11 +571,11 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
571571
time.sleep(0.06)
572572
element = self.wait_for_element_visible(
573573
selector, by=by, timeout=timeout)
574-
if not new_value.endswith('\n'):
575-
element.send_keys(new_value)
574+
if not text.endswith('\n'):
575+
element.send_keys(text)
576576
else:
577-
new_value = new_value[:-1]
578-
element.send_keys(new_value)
577+
text = text[:-1]
578+
element.send_keys(text)
579579
element.send_keys(Keys.RETURN)
580580
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:
581581
self.wait_for_ready_state_complete()
@@ -588,24 +588,27 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
588588
else:
589589
self.__demo_mode_pause_if_active(tiny=True)
590590

591-
def send_keys(self, selector, new_value, by=By.CSS_SELECTOR,
591+
def send_keys(self, selector, text, by=By.CSS_SELECTOR,
592592
timeout=settings.LARGE_TIMEOUT):
593593
""" Same as add_text() -> more reliable, but less name confusion. """
594594
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
595595
timeout = self.__get_new_timeout(timeout)
596596
if page_utils.is_xpath_selector(selector):
597597
by = By.XPATH
598-
self.add_text(selector, new_value, by=by, timeout=timeout)
598+
self.add_text(selector, text, by=by, timeout=timeout)
599599

600-
def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
601-
timeout=settings.LARGE_TIMEOUT, retry=False):
602-
""" This method updates an element's text value with a new value.
600+
def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
601+
timeout=settings.LARGE_TIMEOUT, retry=False):
602+
""" This method updates an element's text field with new text.
603+
Has two parts:
604+
1. Clears the text field.
605+
2. Types in new text into the text field.
603606
@Params
604-
selector - the selector with the value to update
605-
new_value - the new value for setting the text field
606-
by - the type of selector to search by (Default: CSS)
607+
selector - the selector of the text field
608+
new_value - the new value to type into the text field
609+
by - the type of selector to search by (Default: CSS Selector)
607610
timeout - how long to wait for the selector to be visible
608-
retry - if True, use JS if the selenium text update fails
611+
retry - if True, use JS if the Selenium text update fails
609612
"""
610613
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
611614
timeout = self.__get_new_timeout(timeout)
@@ -666,17 +669,16 @@ def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
666669
else:
667670
self.__demo_mode_pause_if_active(tiny=True)
668671

669-
def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
670-
timeout=settings.LARGE_TIMEOUT, retry=False):
671-
""" The shorter version of update_text_value(), which
672-
clears existing text and adds new text into the text field.
672+
def type(self, selector, text, by=By.CSS_SELECTOR,
673+
timeout=settings.LARGE_TIMEOUT, retry=False):
674+
""" The short version of update_text(), which clears existing text
675+
and adds new text into the text field.
673676
We want to keep the old version for backward compatibility. """
674677
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
675678
timeout = self.__get_new_timeout(timeout)
676679
if page_utils.is_xpath_selector(selector):
677680
by = By.XPATH
678-
self.update_text_value(selector, new_value, by=by,
679-
timeout=timeout, retry=retry)
681+
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
680682

681683
def is_element_present(self, selector, by=By.CSS_SELECTOR):
682684
if page_utils.is_xpath_selector(selector):

0 commit comments

Comments
 (0)