Skip to content

Commit 36e71ec

Browse files
committed
Add a shortcut to tab through and click active elements
1 parent 8394e76 commit 36e71ec

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

0 commit comments

Comments
 (0)