@@ -5016,7 +5016,9 @@ def js_click(
5016
5016
element = self.wait_for_element_present(
5017
5017
selector, by=by, timeout=settings.SMALL_TIMEOUT
5018
5018
)
5019
+ scroll_done = False
5019
5020
if self.is_element_visible(selector, by=by):
5021
+ scroll_done = True
5020
5022
self.__demo_mode_highlight_if_active(selector, by)
5021
5023
if scroll and not self.demo_mode and not self.slow_mode:
5022
5024
success = js_utils.scroll_to_element(self.driver, element)
@@ -5050,6 +5052,16 @@ def js_click(
5050
5052
action = ["js_cl", selector, href_origin, time_stamp]
5051
5053
if all_matches:
5052
5054
action[0] = "js_ca"
5055
+ if not self.is_element_visible(selector, by=by):
5056
+ self.wait_for_ready_state_complete()
5057
+ if self.is_element_visible(selector, by=by):
5058
+ if scroll and not scroll_done:
5059
+ success = js_utils.scroll_to_element(self.driver, element)
5060
+ if not success:
5061
+ timeout = settings.SMALL_TIMEOUT
5062
+ element = page_actions.wait_for_element_present(
5063
+ self.driver, selector, by, timeout=timeout
5064
+ )
5053
5065
if not all_matches:
5054
5066
if ":contains\\(" not in css_selector:
5055
5067
self.__js_click(selector, by=by)
@@ -11585,7 +11597,16 @@ def __js_click(self, selector, by="css selector"):
11585
11597
simulateClick(someLink);"""
11586
11598
% css_selector
11587
11599
)
11588
- self.execute_script(script)
11600
+ try:
11601
+ self.execute_script(script)
11602
+ except Exception:
11603
+ # If the regular mouse-simulated click fails, do a basic JS click
11604
+ self.wait_for_ready_state_complete()
11605
+ script = (
11606
+ """document.querySelector('%s').click();"""
11607
+ % css_selector
11608
+ )
11609
+ self.execute_script(script)
11589
11610
11590
11611
def __js_click_all(self, selector, by="css selector"):
11591
11612
"""Clicks all matching elements using pure JS. (No jQuery)"""
0 commit comments