Skip to content

Commit 0d7e9bd

Browse files
authored
Merge pull request #1391 from seleniumbase/pressing-tabs-and-active-elements
Add a shortcut for cycling through elements with the "tab" key and then clicking the active element
2 parents ecb4d20 + 0d86edd commit 0d7e9bd

File tree

7 files changed

+46
-15
lines changed

7 files changed

+46
-15
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- name: Install dependencies
3131
run: |
3232
python -m pip install --upgrade pip
33+
python -m pip install --upgrade wheel
3334
pip install -r requirements.txt
3435
- name: Install SeleniumBase
3536
run: |

examples/test_cycle_elements.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class CycleTests(BaseCase):
5+
def test_cycle_elements_with_tab_and_press_enter(self):
6+
""" Test pressing the tab key to cycle through elements.
7+
Then click on the active element and verify actions.
8+
This can all be performed by using a single command.
9+
The "\t" is the tab key. The "\n" is the RETURN key. """
10+
self.open("seleniumbase.io/demo_page")
11+
self.assert_text("This Text is Green", "#pText")
12+
self.send_keys("html", "\t\t\t\t\n")
13+
self.assert_text("This Text is Purple", "#pText")

help_docs/method_summary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ self.type(selector, text, by="css selector", timeout=None)
3030
# self.fill(selector, text, by="css selector", timeout=None)
3131
# self.write(selector, text, by="css selector", timeout=None)
3232

33-
self.add_text(selector, text, by="css selector", timeout=None)
34-
# Duplicates: self.send_keys(selector, text, by="css selector", timeout=None)
33+
self.send_keys(selector, text, by="css selector", timeout=None)
34+
# Duplicates: self.add_text(selector, text, by="css selector", timeout=None)
3535

3636
self.submit(selector, by="css selector")
3737

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ toml==0.10.2
124124
Pillow==6.2.2;python_version<"3.5"
125125
Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"
126126
Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"
127-
Pillow==9.1.1;python_version>="3.7"
127+
Pillow==9.2.0;python_version>="3.7"
128128
typing-extensions==3.10.0.2;python_version<"3.6"
129129
typing-extensions==4.1.1;python_version>="3.6" and python_version<"3.7"
130130
typing-extensions==4.2.0;python_version>="3.7" and python_version<"3.9"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "3.3.5"
2+
__version__ = "3.3.6"

seleniumbase/fixtures/base_case.py

Lines changed: 27 additions & 10 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)
@@ -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()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
'Pillow==6.2.2;python_version<"3.5"',
252252
'Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"',
253253
'Pillow==8.4.0;python_version>="3.6" and python_version<"3.7"',
254-
'Pillow==9.1.1;python_version>="3.7"',
254+
'Pillow==9.2.0;python_version>="3.7"',
255255
'typing-extensions==3.10.0.2;python_version<"3.6"', # <3.9 for "rich"
256256
'typing-extensions==4.1.1;python_version>="3.6" and python_version<"3.7"', # noqa: E501
257257
'typing-extensions==4.2.0;python_version>="3.7" and python_version<"3.9"', # noqa: E501

0 commit comments

Comments
 (0)