Skip to content

Commit edb593d

Browse files
authored
Merge pull request #686 from seleniumbase/update-methods-that-click-visible-elements
Update methods that click visible elements
2 parents 388cbee + 67fa236 commit edb593d

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

help_docs/method_summary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ self.find_elements(selector, by=By.CSS_SELECTOR, limit=0)
9696

9797
self.find_visible_elements(selector, by=By.CSS_SELECTOR, limit=0)
9898

99-
self.click_visible_elements(selector, by=By.CSS_SELECTOR, limit=0)
99+
self.click_visible_elements(selector, by=By.CSS_SELECTOR, limit=0, timeout=None)
100100

101-
self.click_nth_visible_element(selector, number, by=By.CSS_SELECTOR)
101+
self.click_nth_visible_element(selector, number, by=By.CSS_SELECTOR, timeout=None)
102102

103103
self.click_if_visible(selector, by=By.CSS_SELECTOR)
104104

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pip>=20.2.2
1+
pip>=20.2.3
22
packaging>=20.4
33
setuptools>=44.1.1;python_version<"3.5"
44
setuptools>=50.3.0;python_version>="3.5"

seleniumbase/fixtures/base_case.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,17 +1029,21 @@ def find_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
10291029
v_elems = v_elems[:limit]
10301030
return v_elems
10311031

1032-
def click_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
1032+
def click_visible_elements(
1033+
self, selector, by=By.CSS_SELECTOR, limit=0, timeout=None):
10331034
""" Finds all matching page elements and clicks visible ones in order.
10341035
If a click reloads or opens a new page, the clicking will stop.
10351036
If no matching elements appear, an Exception will be raised.
10361037
If "limit" is set and > 0, will only click that many elements.
10371038
Also clicks elements that become visible from previous clicks.
10381039
Works best for actions such as clicking all checkboxes on a page.
10391040
Example: self.click_visible_elements('input[type="checkbox"]') """
1041+
if not timeout:
1042+
timeout = settings.SMALL_TIMEOUT
1043+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1044+
timeout = self.__get_new_timeout(timeout)
10401045
selector, by = self.__recalculate_selector(selector, by)
1041-
self.wait_for_element_present(
1042-
selector, by=by, timeout=settings.SMALL_TIMEOUT)
1046+
self.wait_for_element_present(selector, by=by, timeout=timeout)
10431047
elements = self.find_elements(selector, by=by)
10441048
if self.browser == "safari":
10451049
if not limit:
@@ -1088,10 +1092,17 @@ def click_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
10881092
except (StaleElementReferenceException, ENI_Exception):
10891093
return # Probably on new page / Elements are all stale
10901094

1091-
def click_nth_visible_element(self, selector, number, by=By.CSS_SELECTOR):
1095+
def click_nth_visible_element(
1096+
self, selector, number, by=By.CSS_SELECTOR, timeout=None):
10921097
""" Finds all matching page elements and clicks the nth visible one.
10931098
Example: self.click_nth_visible_element('[type="checkbox"]', 5)
10941099
(Clicks the 5th visible checkbox on the page.) """
1100+
if not timeout:
1101+
timeout = settings.SMALL_TIMEOUT
1102+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1103+
timeout = self.__get_new_timeout(timeout)
1104+
selector, by = self.__recalculate_selector(selector, by)
1105+
self.wait_for_element_present(selector, by=by, timeout=timeout)
10951106
elements = self.find_visible_elements(selector, by=by)
10961107
if len(elements) < number:
10971108
raise Exception("Not enough matching {%s} elements of type {%s} to"

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
setup(
5656
name='seleniumbase',
57-
version='1.49.4',
57+
version='1.49.5',
5858
description='Web Automation and Test Framework - https://seleniumbase.io',
5959
long_description=long_description,
6060
long_description_content_type='text/markdown',
@@ -90,7 +90,7 @@
9090
"Topic :: Utilities",
9191
],
9292
install_requires=[
93-
'pip>=20.2.2',
93+
'pip>=20.2.3',
9494
'packaging>=20.4',
9595
'setuptools>=44.1.1;python_version<"3.5"',
9696
'setuptools>=50.3.0;python_version>="3.5"',

0 commit comments

Comments
 (0)