@@ -5687,13 +5687,22 @@ def click_xpath(self, xpath):
5687
5687
self.click(xpath, by="xpath")
5688
5688
5689
5689
def js_click(
5690
- self, selector, by="css selector", all_matches=False, scroll=True
5690
+ self,
5691
+ selector,
5692
+ by="css selector",
5693
+ all_matches=False,
5694
+ timeout=None,
5695
+ scroll=True,
5691
5696
):
5692
5697
"""Clicks an element using JavaScript.
5693
5698
Can be used to click hidden / invisible elements.
5694
5699
If "all_matches" is False, only the first match is clicked.
5695
5700
If "scroll" is False, won't scroll unless running in Demo Mode."""
5696
5701
self.wait_for_ready_state_complete()
5702
+ if not timeout or timeout is True:
5703
+ timeout = settings.SMALL_TIMEOUT
5704
+ if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
5705
+ timeout = self.__get_new_timeout(timeout)
5697
5706
selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
5698
5707
if by == By.LINK_TEXT:
5699
5708
message = (
@@ -5706,7 +5715,7 @@ def js_click(
5706
5715
self.click(selector, by=by)
5707
5716
return
5708
5717
element = self.wait_for_element_present(
5709
- selector, by=by, timeout=settings.SMALL_TIMEOUT
5718
+ selector, by=by, timeout=timeout
5710
5719
)
5711
5720
if not page_actions.is_element_clickable(self.driver, selector, by):
5712
5721
self.wait_for_ready_state_complete()
@@ -5818,9 +5827,7 @@ def js_click_if_present(self, selector, by="css selector", timeout=0):
5818
5827
self.js_click(selector, by=by)
5819
5828
elif timeout > 0:
5820
5829
try:
5821
- self.wait_for_element_present(
5822
- selector, by=by, timeout=timeout
5823
- )
5830
+ self.wait_for_element_present(selector, by=by, timeout=timeout)
5824
5831
except Exception:
5825
5832
pass
5826
5833
if self.is_element_present(selector, by=by):
@@ -5836,27 +5843,29 @@ def js_click_if_visible(self, selector, by="css selector", timeout=0):
5836
5843
self.js_click(selector, by=by)
5837
5844
elif timeout > 0:
5838
5845
try:
5839
- self.wait_for_element_visible(
5840
- selector, by=by, timeout=timeout
5841
- )
5846
+ self.wait_for_element_visible(selector, by=by, timeout=timeout)
5842
5847
except Exception:
5843
5848
pass
5844
5849
if self.is_element_visible(selector, by=by):
5845
5850
self.js_click(selector, by=by)
5846
5851
5847
- def js_click_all(self, selector, by="css selector"):
5852
+ def js_click_all(self, selector, by="css selector", timeout=None ):
5848
5853
"""Clicks all matching elements using pure JS. (No jQuery)"""
5849
- self.js_click(selector, by="css selector", all_matches=True)
5854
+ self.js_click(
5855
+ selector, by="css selector", all_matches=True, timeout=timeout
5856
+ )
5850
5857
5851
- def jquery_click(self, selector, by="css selector"):
5858
+ def jquery_click(self, selector, by="css selector", timeout=None ):
5852
5859
"""Clicks an element using jQuery. (Different from using pure JS.)
5853
5860
Can be used to click hidden / invisible elements."""
5854
5861
self.__check_scope()
5862
+ if not timeout or timeout is True:
5863
+ timeout = settings.SMALL_TIMEOUT
5864
+ if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
5865
+ timeout = self.__get_new_timeout(timeout)
5855
5866
original_selector = selector
5856
5867
selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
5857
- self.wait_for_element_present(
5858
- selector, by=by, timeout=settings.SMALL_TIMEOUT
5859
- )
5868
+ self.wait_for_element_present(selector, by=by, timeout=timeout)
5860
5869
if self.is_element_visible(selector, by=by):
5861
5870
self.__demo_mode_highlight_if_active(selector, by)
5862
5871
selector = self.convert_to_css_selector(selector, by=by)
@@ -5887,14 +5896,16 @@ def jquery_click(self, selector, by="css selector"):
5887
5896
self.safe_execute_script(click_script)
5888
5897
self.__demo_mode_pause_if_active()
5889
5898
5890
- def jquery_click_all(self, selector, by="css selector"):
5899
+ def jquery_click_all(self, selector, by="css selector", timeout=None ):
5891
5900
"""Clicks all matching elements using jQuery."""
5892
5901
self.__check_scope()
5902
+ if not timeout or timeout is True:
5903
+ timeout = settings.SMALL_TIMEOUT
5904
+ if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
5905
+ timeout = self.__get_new_timeout(timeout)
5893
5906
original_selector = selector
5894
5907
selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
5895
- self.wait_for_element_present(
5896
- selector, by=by, timeout=settings.SMALL_TIMEOUT
5897
- )
5908
+ self.wait_for_element_present(selector, by=by, timeout=timeout)
5898
5909
if self.is_element_visible(selector, by=by):
5899
5910
self.__demo_mode_highlight_if_active(selector, by)
5900
5911
css_selector = self.convert_to_css_selector(selector, by=by)
0 commit comments