Skip to content

Commit 2bf4a78

Browse files
authored
Merge pull request #252 from seleniumbase/add-click-visible-elements
Add click_visible_elements(selector) method
2 parents 4df7fad + 7189d65 commit 2bf4a78

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ self.find_elements(selector, by=By.CSS_SELECTOR)
7575

7676
self.find_visible_elements(selector, by=By.CSS_SELECTOR)
7777

78+
self.click_visible_elements(selector, by=By.CSS_SELECTOR)
79+
7880
self.is_element_in_an_iframe(selector, by=By.CSS_SELECTOR)
7981

8082
self.switch_to_frame_of_element(selector, by=By.CSS_SELECTOR)

seleniumbase/config/proxy_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
Example proxies in PROXY_LIST below are not guaranteed to be active or secure.
1616
If you don't already have a proxy server to connect to,
1717
you can try finding one from one of following sites:
18-
* https://www.proxynova.com/proxy-server-list/port-8080/
18+
* https://www.proxynova.com/proxy-server-list/country-us/
1919
* https://www.us-proxy.org/
2020
* https://hidemy.name/en/proxy-list/?country=US&type=h#list
2121
* http://proxyservers.pro/proxy/list/protocol/http/country/US/
2222
"""
2323

2424
PROXY_LIST = {
25-
"example1": "104.248.122.30:8080", # (Example) - set your own proxy here
25+
"example1": "192.241.132.219:80", # (Example) - set your own proxy here
2626
"proxy1": None,
2727
"proxy2": None,
2828
"proxy3": None,

seleniumbase/fixtures/base_case.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,36 @@ def find_visible_elements(self, selector, by=By.CSS_SELECTOR):
663663
by = By.LINK_TEXT
664664
return page_actions.find_visible_elements(self.driver, selector, by)
665665

666+
def click_visible_elements(self, selector, by=By.CSS_SELECTOR):
667+
""" Finds all matching page elements and clicks visible ones in order.
668+
If a click reloads or opens a new page, the clicking will stop.
669+
Works best for actions such as clicking all checkboxes on a page.
670+
Example: self.click_visible_elements('input[type="checkbox"]')
671+
"""
672+
elements = self.find_elements(selector, by=by)
673+
count = 0
674+
for element in elements:
675+
count += 1
676+
if count == 1:
677+
self.wait_for_ready_state_complete()
678+
if self.is_element_visible(selector, by=by):
679+
self.click(selector, by=by)
680+
else:
681+
self.wait_for_ready_state_complete()
682+
try:
683+
if element.is_displayed():
684+
self.__scroll_to_element(element)
685+
element.click()
686+
except (StaleElementReferenceException, ENI_Exception):
687+
self.wait_for_ready_state_complete()
688+
time.sleep(0.05)
689+
try:
690+
if element.is_displayed():
691+
self.__scroll_to_element(element)
692+
element.click()
693+
except (StaleElementReferenceException, ENI_Exception):
694+
return # Probably on new page / Elements are all stale
695+
666696
def is_element_in_an_iframe(self, selector, by=By.CSS_SELECTOR):
667697
""" Returns True if the selector's element is located in an iframe.
668698
Otherwise returns False. """

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.17.8',
20+
version='1.17.9',
2121
description='All-in-One Test Automation Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)