@@ -649,9 +649,25 @@ def add_text(self, selector, text, by="css selector", timeout=None):
649649 if self.__is_shadow_selector(selector):
650650 self.__shadow_type(selector, text, timeout, clear_first=False)
651651 return
652+ if selector == "html" and text in ["\n", Keys.ENTER, Keys.RETURN]:
653+ # This is a shortcut for calling self.click_active_element().
654+ # Use after "\t" or Keys.TAB to cycle through elements first.
655+ self.click_active_element()
656+ return
652657 element = self.wait_for_element_visible(
653658 selector, by=by, timeout=timeout
654659 )
660+ if (
661+ selector == "html" and text.count("\t") >= 1
662+ and text.count("\n") == 1 and text.endswith("\n")
663+ and text.replace("\t", "").replace("\n", "").replace(" ", "") == ""
664+ ):
665+ # Shortcut to send multiple tabs followed by click_active_element()
666+ self.wait_for_ready_state_complete()
667+ for tab in range(text.count("\t")):
668+ element.send_keys("\t")
669+ self.click_active_element()
670+ return
655671 self.__demo_mode_highlight_if_active(selector, by)
656672 if not self.demo_mode and not self.slow_mode:
657673 self.__scroll_to_element(element, selector, by)
@@ -713,6 +729,17 @@ def type(
713729 selector, by = self.__recalculate_selector(selector, by)
714730 self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
715731
732+ def send_keys(self, selector, text, by="css selector", timeout=None):
733+ """Same as self.add_text()
734+ Similar to update_text(), but won't clear the text field first."""
735+ self.__check_scope()
736+ if not timeout:
737+ timeout = settings.LARGE_TIMEOUT
738+ if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
739+ timeout = self.__get_new_timeout(timeout)
740+ selector, by = self.__recalculate_selector(selector, by)
741+ self.add_text(selector, text, by=by, timeout=timeout)
742+
716743 def submit(self, selector, by="css selector"):
717744 """Alternative to self.driver.find_element_by_*(SELECTOR).submit()"""
718745 self.__check_scope()
@@ -7317,16 +7344,6 @@ def write(
73177344 selector, by = self.__recalculate_selector(selector, by)
73187345 self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
73197346
7320- def send_keys(self, selector, text, by="css selector", timeout=None):
7321- """Same as self.add_text()"""
7322- self.__check_scope()
7323- if not timeout:
7324- timeout = settings.LARGE_TIMEOUT
7325- if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
7326- timeout = self.__get_new_timeout(timeout)
7327- selector, by = self.__recalculate_selector(selector, by)
7328- self.add_text(selector, text, by=by, timeout=timeout)
7329-
73307347 def click_link(self, link_text, timeout=None):
73317348 """Same as self.click_link_text()"""
73327349 self.__check_scope()
0 commit comments