@@ -543,7 +543,7 @@ def get_image_url(self, selector, by=By.CSS_SELECTOR,
543
543
return self .get_attribute (selector ,
544
544
attribute = 'src' , by = by , timeout = timeout )
545
545
546
- def add_text (self , selector , new_value , by = By .CSS_SELECTOR ,
546
+ def add_text (self , selector , text , by = By .CSS_SELECTOR ,
547
547
timeout = settings .LARGE_TIMEOUT ):
548
548
""" The more-reliable version of driver.send_keys()
549
549
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,
558
558
self .__scroll_to_element (element )
559
559
pre_action_url = self .driver .current_url
560
560
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 )
563
563
else :
564
- new_value = new_value [:- 1 ]
565
- element .send_keys (new_value )
564
+ text = text [:- 1 ]
565
+ element .send_keys (text )
566
566
element .send_keys (Keys .RETURN )
567
567
if settings .WAIT_FOR_RSC_ON_PAGE_LOADS :
568
568
self .wait_for_ready_state_complete ()
@@ -571,11 +571,11 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
571
571
time .sleep (0.06 )
572
572
element = self .wait_for_element_visible (
573
573
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 )
576
576
else :
577
- new_value = new_value [:- 1 ]
578
- element .send_keys (new_value )
577
+ text = text [:- 1 ]
578
+ element .send_keys (text )
579
579
element .send_keys (Keys .RETURN )
580
580
if settings .WAIT_FOR_RSC_ON_PAGE_LOADS :
581
581
self .wait_for_ready_state_complete ()
@@ -588,24 +588,27 @@ def add_text(self, selector, new_value, by=By.CSS_SELECTOR,
588
588
else :
589
589
self .__demo_mode_pause_if_active (tiny = True )
590
590
591
- def send_keys (self , selector , new_value , by = By .CSS_SELECTOR ,
591
+ def send_keys (self , selector , text , by = By .CSS_SELECTOR ,
592
592
timeout = settings .LARGE_TIMEOUT ):
593
593
""" Same as add_text() -> more reliable, but less name confusion. """
594
594
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
595
595
timeout = self .__get_new_timeout (timeout )
596
596
if page_utils .is_xpath_selector (selector ):
597
597
by = By .XPATH
598
- self .add_text (selector , new_value , by = by , timeout = timeout )
598
+ self .add_text (selector , text , by = by , timeout = timeout )
599
599
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.
603
606
@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 )
607
610
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
609
612
"""
610
613
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
611
614
timeout = self .__get_new_timeout (timeout )
@@ -666,17 +669,16 @@ def update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
666
669
else :
667
670
self .__demo_mode_pause_if_active (tiny = True )
668
671
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.
673
676
We want to keep the old version for backward compatibility. """
674
677
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
675
678
timeout = self .__get_new_timeout (timeout )
676
679
if page_utils .is_xpath_selector (selector ):
677
680
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 )
680
682
681
683
def is_element_present (self , selector , by = By .CSS_SELECTOR ):
682
684
if page_utils .is_xpath_selector (selector ):
0 commit comments