@@ -60,6 +60,7 @@ def test_anything(self):
6060logging .getLogger ("urllib3" ).setLevel (logging .ERROR )
6161urllib3 .disable_warnings ()
6262LOGGER .setLevel (logging .WARNING )
63+ ECI_Exception = selenium_exceptions .ElementClickInterceptedException
6364ENI_Exception = selenium_exceptions .ElementNotInteractableException
6465
6566
@@ -951,10 +952,11 @@ def get_image_url(self, selector, by=By.CSS_SELECTOR, timeout=None):
951952
952953 def find_elements (self , selector , by = By .CSS_SELECTOR , limit = 0 ):
953954 """ Returns a list of matching WebElements.
955+ Elements could be either hidden or visible on the page.
954956 If "limit" is set and > 0, will only return that many elements. """
955- self .wait_for_ready_state_complete ()
956- time .sleep (0.05 )
957957 selector , by = self .__recalculate_selector (selector , by )
958+ self .wait_for_ready_state_complete ()
959+ time .sleep (0.07 )
958960 elements = self .driver .find_elements (by = by , value = selector )
959961 if limit and limit > 0 and len (elements ) > limit :
960962 elements = elements [:limit ]
@@ -963,9 +965,9 @@ def find_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
963965 def find_visible_elements (self , selector , by = By .CSS_SELECTOR , limit = 0 ):
964966 """ Returns a list of matching WebElements that are visible.
965967 If "limit" is set and > 0, will only return that many elements. """
966- self .wait_for_ready_state_complete ()
967- time .sleep (0.05 )
968968 selector , by = self .__recalculate_selector (selector , by )
969+ self .wait_for_ready_state_complete ()
970+ time .sleep (0.07 )
969971 v_elems = page_actions .find_visible_elements (self .driver , selector , by )
970972 if limit and limit > 0 and len (v_elems ) > limit :
971973 v_elems = v_elems [:limit ]
@@ -977,35 +979,34 @@ def click_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
977979 Works best for actions such as clicking all checkboxes on a page.
978980 Example: self.click_visible_elements('input[type="checkbox"]')
979981 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 )
982987 click_count = 0
983988 for element in elements :
984989 if limit and limit > 0 and click_count >= limit :
985990 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 ()
991995 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 ):
9931000 self .wait_for_ready_state_complete ()
1001+ time .sleep (0.03 )
9941002 try :
9951003 if element .is_displayed ():
9961004 self .__scroll_to_element (element )
9971005 element .click ()
9981006 click_count += 1
1007+ self .wait_for_ready_state_complete ()
9991008 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
10091010
10101011 def click_nth_visible_element (self , selector , number , by = By .CSS_SELECTOR ):
10111012 """ 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):
10511052 iframe_identifier = iframe ['name' ]
10521053 elif iframe .has_attr ('id' ) and len (iframe ['id' ]) > 0 :
10531054 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
10541058 else :
10551059 continue
10561060 self .switch_to_frame (iframe_identifier )
0 commit comments