@@ -947,6 +947,7 @@ def find_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
947947 """ Returns a list of matching WebElements.
948948 If "limit" is set and > 0, will only return that many elements. """
949949 self .wait_for_ready_state_complete ()
950+ time .sleep (0.05 )
950951 selector , by = self .__recalculate_selector (selector , by )
951952 elements = self .driver .find_elements (by = by , value = selector )
952953 if limit and limit > 0 and len (elements ) > limit :
@@ -957,6 +958,7 @@ def find_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
957958 """ Returns a list of matching WebElements that are visible.
958959 If "limit" is set and > 0, will only return that many elements. """
959960 self .wait_for_ready_state_complete ()
961+ time .sleep (0.05 )
960962 selector , by = self .__recalculate_selector (selector , by )
961963 v_elems = page_actions .find_visible_elements (self .driver , selector , by )
962964 if limit and limit > 0 and len (v_elems ) > limit :
@@ -999,6 +1001,28 @@ def click_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
9991001 except (StaleElementReferenceException , ENI_Exception ):
10001002 return # Probably on new page / Elements are all stale
10011003
1004+ def click_nth_visible_element (self , selector , number , by = By .CSS_SELECTOR ):
1005+ """ Finds all matching page elements and clicks the nth visible one.
1006+ Example: self.click_nth_visible_element('[type="checkbox"]', 5)
1007+ (Clicks the 5th visible checkbox on the page.) """
1008+ elements = self .find_visible_elements (selector , by = by )
1009+ if len (elements ) < number :
1010+ raise Exception ("Not enough matching {%s} elements of type {%s} to"
1011+ " click number %s!" % (selector , by , number ))
1012+ number = number - 1
1013+ if number < 0 :
1014+ number = 0
1015+ element = elements [number ]
1016+ self .wait_for_ready_state_complete ()
1017+ try :
1018+ self .__scroll_to_element (element )
1019+ element .click ()
1020+ except (StaleElementReferenceException , ENI_Exception ):
1021+ self .wait_for_ready_state_complete ()
1022+ time .sleep (0.05 )
1023+ self .__scroll_to_element (element )
1024+ element .click ()
1025+
10021026 def click_if_visible (self , selector , by = By .CSS_SELECTOR ):
10031027 """ If the page selector exists and is visible, clicks on the element.
10041028 This method only clicks on the first matching element found.
0 commit comments