@@ -5016,6 +5016,8 @@ def js_click(
5016
5016
element = self.wait_for_element_present(
5017
5017
selector, by=by, timeout=settings.SMALL_TIMEOUT
5018
5018
)
5019
+ if not page_actions.is_element_clickable(self.driver, selector, by):
5020
+ self.wait_for_ready_state_complete()
5019
5021
scroll_done = False
5020
5022
if self.is_element_visible(selector, by=by):
5021
5023
scroll_done = True
@@ -11584,6 +11586,8 @@ def __js_click(self, selector, by="css selector"):
11584
11586
css_selector = self.convert_to_css_selector(selector, by=by)
11585
11587
css_selector = re.escape(css_selector) # Add "\\" to special chars
11586
11588
css_selector = self.__escape_quotes_if_needed(css_selector)
11589
+ is_visible = self.is_element_visible(selector, by=by)
11590
+ current_url = self.get_current_url()
11587
11591
script = (
11588
11592
"""var simulateClick = function (elem) {
11589
11593
var evt = new MouseEvent('click', {
@@ -11600,10 +11604,18 @@ def __js_click(self, selector, by="css selector"):
11600
11604
try:
11601
11605
self.execute_script(script)
11602
11606
except Exception as e:
11607
+ # If element was visible but no longer, or on a different page now,
11608
+ # assume that the click actually worked and continue with the test.
11609
+ if (
11610
+ (is_visible and not self.is_element_visible(selector, by=by))
11611
+ or current_url != self.get_current_url()
11612
+ ):
11613
+ return # The click worked, but threw an Exception. Keep going.
11614
+ # It appears the first click didn't work. Make another attempt.
11603
11615
self.wait_for_ready_state_complete()
11604
11616
if "Cannot read properties of null" in e.msg:
11605
11617
page_actions.wait_for_element_present(
11606
- self.driver, selector, by, timeout=3
11618
+ self.driver, selector, by, timeout=5
11607
11619
)
11608
11620
if not page_actions.is_element_clickable(
11609
11621
self.driver, selector, by
0 commit comments