@@ -60,6 +60,7 @@ def test_anything(self):
60
60
logging .getLogger ("urllib3" ).setLevel (logging .ERROR )
61
61
urllib3 .disable_warnings ()
62
62
LOGGER .setLevel (logging .WARNING )
63
+ ECI_Exception = selenium_exceptions .ElementClickInterceptedException
63
64
ENI_Exception = selenium_exceptions .ElementNotInteractableException
64
65
65
66
@@ -951,10 +952,11 @@ def get_image_url(self, selector, by=By.CSS_SELECTOR, timeout=None):
951
952
952
953
def find_elements (self , selector , by = By .CSS_SELECTOR , limit = 0 ):
953
954
""" Returns a list of matching WebElements.
955
+ Elements could be either hidden or visible on the page.
954
956
If "limit" is set and > 0, will only return that many elements. """
955
- self .wait_for_ready_state_complete ()
956
- time .sleep (0.05 )
957
957
selector , by = self .__recalculate_selector (selector , by )
958
+ self .wait_for_ready_state_complete ()
959
+ time .sleep (0.07 )
958
960
elements = self .driver .find_elements (by = by , value = selector )
959
961
if limit and limit > 0 and len (elements ) > limit :
960
962
elements = elements [:limit ]
@@ -963,9 +965,9 @@ def find_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
963
965
def find_visible_elements (self , selector , by = By .CSS_SELECTOR , limit = 0 ):
964
966
""" Returns a list of matching WebElements that are visible.
965
967
If "limit" is set and > 0, will only return that many elements. """
966
- self .wait_for_ready_state_complete ()
967
- time .sleep (0.05 )
968
968
selector , by = self .__recalculate_selector (selector , by )
969
+ self .wait_for_ready_state_complete ()
970
+ time .sleep (0.07 )
969
971
v_elems = page_actions .find_visible_elements (self .driver , selector , by )
970
972
if limit and limit > 0 and len (v_elems ) > limit :
971
973
v_elems = v_elems [:limit ]
@@ -977,35 +979,34 @@ def click_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
977
979
Works best for actions such as clicking all checkboxes on a page.
978
980
Example: self.click_visible_elements('input[type="checkbox"]')
979
981
If "limit" is set and > 0, will only click that many elements. """
980
- elements = self .find_elements (selector , by = by )
981
- count = 0
982
+ elements = []
983
+ try :
984
+ elements = self .find_visible_elements (selector , by = by )
985
+ except Exception :
986
+ elements = self .find_elements (selector , by = by )
982
987
click_count = 0
983
988
for element in elements :
984
989
if limit and limit > 0 and click_count >= limit :
985
990
return
986
- count += 1
987
- if count == 1 :
988
- self .wait_for_ready_state_complete ()
989
- if self .is_element_visible (selector , by = by ):
990
- self .click (selector , by = by )
991
+ try :
992
+ if element .is_displayed ():
993
+ self .__scroll_to_element (element )
994
+ element .click ()
991
995
click_count += 1
992
- else :
996
+ self .wait_for_ready_state_complete ()
997
+ except ECI_Exception :
998
+ continue # ElementClickInterceptedException (Overlay likely)
999
+ except (StaleElementReferenceException , ENI_Exception ):
993
1000
self .wait_for_ready_state_complete ()
1001
+ time .sleep (0.03 )
994
1002
try :
995
1003
if element .is_displayed ():
996
1004
self .__scroll_to_element (element )
997
1005
element .click ()
998
1006
click_count += 1
1007
+ self .wait_for_ready_state_complete ()
999
1008
except (StaleElementReferenceException , ENI_Exception ):
1000
- self .wait_for_ready_state_complete ()
1001
- time .sleep (0.05 )
1002
- try :
1003
- if element .is_displayed ():
1004
- self .__scroll_to_element (element )
1005
- element .click ()
1006
- click_count += 1
1007
- except (StaleElementReferenceException , ENI_Exception ):
1008
- return # Probably on new page / Elements are all stale
1009
+ return # Probably on new page / Elements are all stale
1009
1010
1010
1011
def click_nth_visible_element (self , selector , number , by = By .CSS_SELECTOR ):
1011
1012
""" Finds all matching page elements and clicks the nth visible one.
@@ -1051,6 +1052,9 @@ def is_element_in_an_iframe(self, selector, by=By.CSS_SELECTOR):
1051
1052
iframe_identifier = iframe ['name' ]
1052
1053
elif iframe .has_attr ('id' ) and len (iframe ['id' ]) > 0 :
1053
1054
iframe_identifier = iframe ['id' ]
1055
+ elif iframe .has_attr ('class' ) and len (iframe ['class' ]) > 0 :
1056
+ iframe_class = " " .join (iframe ["class" ])
1057
+ iframe_identifier = '[class="%s"]' % iframe_class
1054
1058
else :
1055
1059
continue
1056
1060
self .switch_to_frame (iframe_identifier )
0 commit comments