@@ -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