@@ -411,7 +411,7 @@ def click(
411411 original_by = by
412412 selector, by = self.__recalculate_selector(selector, by)
413413 if self.__is_cdp_swap_needed():
414- self.cdp.click(selector, timeout=timeout)
414+ self.cdp.click(selector, timeout=timeout, scroll=scroll )
415415 return
416416 if delay and (type(delay) in [int, float]) and delay > 0:
417417 time.sleep(delay)
@@ -2254,7 +2254,7 @@ def find_visible_elements(self, selector, by="css selector", limit=0):
22542254 )
22552255
22562256 def click_visible_elements(
2257- self, selector, by="css selector", limit=0, timeout=None
2257+ self, selector, by="css selector", limit=0, timeout=None, scroll=True
22582258 ):
22592259 """Finds all matching page elements and clicks visible ones in order.
22602260 If a click reloads or opens a new page, the clicking will stop.
@@ -2270,7 +2270,7 @@ def click_visible_elements(
22702270 timeout = self.__get_new_timeout(timeout)
22712271 selector, by = self.__recalculate_selector(selector, by)
22722272 if self.__is_cdp_swap_needed():
2273- self.cdp.click_visible_elements(selector, limit)
2273+ self.cdp.click_visible_elements(selector, limit, scroll=scroll )
22742274 return
22752275 self.wait_for_ready_state_complete()
22762276 if self.__needs_minimum_wait():
@@ -2297,7 +2297,8 @@ def click_visible_elements(
22972297 return
22982298 try:
22992299 if element.is_displayed():
2300- self.__scroll_to_element(element)
2300+ if scroll:
2301+ self.__scroll_to_element(element)
23012302 if self.browser == "safari":
23022303 self.execute_script("arguments[0].click();", element)
23032304 else:
@@ -2311,7 +2312,8 @@ def click_visible_elements(
23112312 time.sleep(0.12)
23122313 try:
23132314 if element.is_displayed():
2314- self.__scroll_to_element(element)
2315+ if scroll:
2316+ self.__scroll_to_element(element)
23152317 if self.browser == "safari":
23162318 self.execute_script(
23172319 "arguments[0].click();", element
@@ -2348,7 +2350,7 @@ def click_visible_elements(
23482350 self.__switch_to_newest_window_if_not_blank()
23492351
23502352 def click_nth_visible_element(
2351- self, selector, number, by="css selector", timeout=None
2353+ self, selector, number, by="css selector", timeout=None, scroll=True
23522354 ):
23532355 """Finds all matching page elements and clicks the nth visible one.
23542356 Example: self.click_nth_visible_element('[type="checkbox"]', 5)
@@ -2360,7 +2362,7 @@ def click_nth_visible_element(
23602362 timeout = self.__get_new_timeout(timeout)
23612363 selector, by = self.__recalculate_selector(selector, by)
23622364 if self.__is_cdp_swap_needed():
2363- self.cdp.click_nth_visible_element(selector, number)
2365+ self.cdp.click_nth_visible_element(selector, number, scroll=scroll )
23642366 return
23652367 self.wait_for_ready_state_complete()
23662368 self.wait_for_element_present(selector, by=by, timeout=timeout)
@@ -2379,7 +2381,8 @@ def click_nth_visible_element(
23792381 pre_action_url = self.driver.current_url
23802382 pre_window_count = len(self.driver.window_handles)
23812383 try:
2382- self.__scroll_to_element(element)
2384+ if scroll:
2385+ self.__scroll_to_element(element)
23832386 self.__element_click(element)
23842387 except (Stale_Exception, ENI_Exception, ECI_Exception):
23852388 time.sleep(0.12)
@@ -2409,26 +2412,28 @@ def click_nth_visible_element(
24092412 ):
24102413 self.__switch_to_newest_window_if_not_blank()
24112414
2412- def click_if_visible(self, selector, by="css selector", timeout=0):
2415+ def click_if_visible(
2416+ self, selector, by="css selector", timeout=0, scroll=True
2417+ ):
24132418 """If the page selector exists and is visible, clicks on the element.
24142419 This method only clicks on the first matching element found.
24152420 Use click_visible_elements() to click all matching elements.
24162421 If a "timeout" is provided, waits that long for the element
24172422 to appear before giving up and returning without a click()."""
24182423 if self.__is_cdp_swap_needed():
2419- self.cdp.click_if_visible(selector, timeout=timeout)
2424+ self.cdp.click_if_visible(selector, timeout=timeout, scroll=scroll )
24202425 return
24212426 self.wait_for_ready_state_complete()
24222427 if self.is_element_visible(selector, by=by):
2423- self.click(selector, by=by)
2428+ self.click(selector, by=by, scroll=scroll )
24242429 elif timeout > 0:
24252430 with suppress(Exception):
24262431 self.wait_for_element_visible(
24272432 selector, by=by, timeout=timeout
24282433 )
24292434 self.sleep(0.2)
24302435 if self.is_element_visible(selector, by=by):
2431- self.click(selector, by=by)
2436+ self.click(selector, by=by, scroll=scroll )
24322437
24332438 def click_active_element(self):
24342439 if self.__is_cdp_swap_needed():
@@ -2484,6 +2489,7 @@ def click_with_offset(
24842489 mark=None,
24852490 timeout=None,
24862491 center=None,
2492+ scroll=True,
24872493 ):
24882494 """Click an element at an {X,Y}-offset location.
24892495 {0,0} is the top-left corner of the element.
@@ -2500,6 +2506,7 @@ def click_with_offset(
25002506 mark=mark,
25012507 timeout=timeout,
25022508 center=center,
2509+ scroll=scroll,
25032510 )
25042511
25052512 def double_click_with_offset(
@@ -2511,6 +2518,7 @@ def double_click_with_offset(
25112518 mark=None,
25122519 timeout=None,
25132520 center=None,
2521+ scroll=True,
25142522 ):
25152523 """Double click an element at an {X,Y}-offset location.
25162524 {0,0} is the top-left corner of the element.
@@ -2527,6 +2535,7 @@ def double_click_with_offset(
25272535 mark=mark,
25282536 timeout=timeout,
25292537 center=center,
2538+ scroll=scroll,
25302539 )
25312540
25322541 def is_checked(self, selector, by="css selector", timeout=None):
@@ -14043,9 +14052,12 @@ def __click_with_offset(
1404314052 mark=None,
1404414053 timeout=None,
1404514054 center=None,
14055+ scroll=True,
1404614056 ):
1404714057 if self.__is_cdp_swap_needed():
14048- self.cdp.click_with_offset(selector, x, y, center=center)
14058+ self.cdp.click_with_offset(
14059+ selector, x, y, center=center, scroll=scroll
14060+ )
1404914061 return
1405014062 self.wait_for_ready_state_complete()
1405114063 if self.__needs_minimum_wait():
@@ -14061,9 +14073,13 @@ def __click_with_offset(
1406114073 if self.demo_mode:
1406214074 self.__highlight(selector, by=by, loops=1)
1406314075 elif self.slow_mode:
14064- self.__slow_scroll_to_element(element)
14076+ if scroll:
14077+ self.__slow_scroll_to_element(element)
14078+ else:
14079+ self.sleep(0.2)
1406514080 else:
14066- self.__scroll_to_element(element, selector, by)
14081+ if scroll:
14082+ self.__scroll_to_element(element, selector, by)
1406714083 self.wait_for_ready_state_complete()
1406814084 if self.__needs_minimum_wait():
1406914085 time.sleep(0.03)
0 commit comments