@@ -127,14 +127,14 @@ def get_event_loop(self):
127
127
def add_handler (self , event , handler ):
128
128
self .page .add_handler (event , handler )
129
129
130
- def find_element (
131
- self , selector , best_match = False , timeout = settings .SMALL_TIMEOUT
132
- ):
130
+ def find_element (self , selector , best_match = False , timeout = None ):
133
131
"""Similar to select(), but also finds elements by text content.
134
132
When using text-based searches, if best_match=False, then will
135
133
find the first element with the text. If best_match=True, then
136
134
if multiple elements have that text, then will use the element
137
135
with the closest text-length to the text being searched for."""
136
+ if not timeout :
137
+ timeout = settings .SMALL_TIMEOUT
138
138
self .__add_light_pause ()
139
139
selector = self .__convert_to_css_if_xpath (selector )
140
140
early_failure = False
@@ -167,12 +167,12 @@ def find_element(
167
167
self .__slow_mode_pause_if_set ()
168
168
return element
169
169
170
- def find_element_by_text (
171
- self , text , tag_name = None , timeout = settings .SMALL_TIMEOUT
172
- ):
170
+ def find_element_by_text (self , text , tag_name = None , timeout = None ):
173
171
"""Returns an element by matching text.
174
172
Optionally, provide a tag_name to narrow down the search to an
175
173
element with the given tag. (Eg: a, button, div, script, span)"""
174
+ if not timeout :
175
+ timeout = settings .SMALL_TIMEOUT
176
176
self .__add_light_pause ()
177
177
time_now = time .time ()
178
178
self .assert_text (text , timeout = timeout )
@@ -218,7 +218,9 @@ def find_element_by_text(
218
218
% (text , tag_name , timeout , plural )
219
219
)
220
220
221
- def find_all (self , selector , timeout = settings .SMALL_TIMEOUT ):
221
+ def find_all (self , selector , timeout = None ):
222
+ if not timeout :
223
+ timeout = settings .SMALL_TIMEOUT
222
224
self .__add_light_pause ()
223
225
selector = self .__convert_to_css_if_xpath (selector )
224
226
elements = self .loop .run_until_complete (
@@ -272,8 +274,10 @@ def find_elements_by_text(self, text, tag_name=None):
272
274
updated_elements .append (element )
273
275
return updated_elements
274
276
275
- def select (self , selector , timeout = settings . SMALL_TIMEOUT ):
277
+ def select (self , selector , timeout = None ):
276
278
"""Similar to find_element(), but without text-based search."""
279
+ if not timeout :
280
+ timeout = settings .SMALL_TIMEOUT
277
281
self .__add_light_pause ()
278
282
selector = self .__convert_to_css_if_xpath (selector )
279
283
if (":contains(" in selector ):
@@ -307,7 +311,9 @@ def select(self, selector, timeout=settings.SMALL_TIMEOUT):
307
311
self .__slow_mode_pause_if_set ()
308
312
return element
309
313
310
- def select_all (self , selector , timeout = settings .SMALL_TIMEOUT ):
314
+ def select_all (self , selector , timeout = None ):
315
+ if not timeout :
316
+ timeout = settings .SMALL_TIMEOUT
311
317
self .__add_light_pause ()
312
318
selector = self .__convert_to_css_if_xpath (selector )
313
319
elements = self .loop .run_until_complete (
@@ -319,10 +325,14 @@ def select_all(self, selector, timeout=settings.SMALL_TIMEOUT):
319
325
updated_elements .append (element )
320
326
return updated_elements
321
327
322
- def find_elements (self , selector , timeout = settings .SMALL_TIMEOUT ):
328
+ def find_elements (self , selector , timeout = None ):
329
+ if not timeout :
330
+ timeout = settings .SMALL_TIMEOUT
323
331
return self .select_all (selector , timeout = timeout )
324
332
325
- def find_visible_elements (self , selector , timeout = settings .SMALL_TIMEOUT ):
333
+ def find_visible_elements (self , selector , timeout = None ):
334
+ if not timeout :
335
+ timeout = settings .SMALL_TIMEOUT
326
336
visible_elements = []
327
337
elements = self .select_all (selector , timeout = timeout )
328
338
for element in elements :
@@ -587,12 +597,12 @@ def load_cookies(self, *args, **kwargs):
587
597
driver .cookies .load (* args , ** kwargs )
588
598
)
589
599
590
- def clear_cookies (self , * args , ** kwargs ):
600
+ def clear_cookies (self ):
591
601
driver = self .driver
592
602
if hasattr (driver , "cdp_base" ):
593
603
driver = driver .cdp_base
594
604
return self .loop .run_until_complete (
595
- driver .cookies .clear (* args , ** kwargs )
605
+ driver .cookies .clear ()
596
606
)
597
607
598
608
def sleep (self , seconds ):
@@ -616,7 +626,9 @@ def get_active_element_css(self):
616
626
self .page .evaluate (js_code )
617
627
)
618
628
619
- def click (self , selector , timeout = settings .SMALL_TIMEOUT ):
629
+ def click (self , selector , timeout = None ):
630
+ if not timeout :
631
+ timeout = settings .SMALL_TIMEOUT
620
632
self .__slow_mode_pause_if_set ()
621
633
element = self .find_element (selector , timeout = timeout )
622
634
element .scroll_into_view ()
@@ -672,8 +684,10 @@ def click_visible_elements(self, selector, limit=0):
672
684
except Exception :
673
685
break
674
686
675
- def mouse_click (self , selector , timeout = settings . SMALL_TIMEOUT ):
687
+ def mouse_click (self , selector , timeout = None ):
676
688
"""(Attempt simulating a mouse click)"""
689
+ if not timeout :
690
+ timeout = settings .SMALL_TIMEOUT
677
691
self .__slow_mode_pause_if_set ()
678
692
element = self .find_element (selector , timeout = timeout )
679
693
element .scroll_into_view ()
@@ -771,7 +785,9 @@ def remove_elements(self, selector):
771
785
with suppress (Exception ):
772
786
self .loop .run_until_complete (self .page .evaluate (js_code ))
773
787
774
- def send_keys (self , selector , text , timeout = settings .SMALL_TIMEOUT ):
788
+ def send_keys (self , selector , text , timeout = None ):
789
+ if not timeout :
790
+ timeout = settings .SMALL_TIMEOUT
775
791
self .__slow_mode_pause_if_set ()
776
792
element = self .select (selector , timeout = timeout )
777
793
element .scroll_into_view ()
@@ -781,8 +797,10 @@ def send_keys(self, selector, text, timeout=settings.SMALL_TIMEOUT):
781
797
self .__slow_mode_pause_if_set ()
782
798
self .loop .run_until_complete (self .page .wait ())
783
799
784
- def press_keys (self , selector , text , timeout = settings . SMALL_TIMEOUT ):
800
+ def press_keys (self , selector , text , timeout = None ):
785
801
"""Similar to send_keys(), but presses keys at human speed."""
802
+ if not timeout :
803
+ timeout = settings .SMALL_TIMEOUT
786
804
self .__slow_mode_pause_if_set ()
787
805
element = self .select (selector , timeout = timeout )
788
806
element .scroll_into_view ()
@@ -799,8 +817,10 @@ def press_keys(self, selector, text, timeout=settings.SMALL_TIMEOUT):
799
817
self .__slow_mode_pause_if_set ()
800
818
self .loop .run_until_complete (self .page .wait ())
801
819
802
- def type (self , selector , text , timeout = settings . SMALL_TIMEOUT ):
820
+ def type (self , selector , text , timeout = None ):
803
821
"""Similar to send_keys(), but clears the text field first."""
822
+ if not timeout :
823
+ timeout = settings .SMALL_TIMEOUT
804
824
self .__slow_mode_pause_if_set ()
805
825
element = self .select (selector , timeout = timeout )
806
826
element .scroll_into_view ()
@@ -812,8 +832,10 @@ def type(self, selector, text, timeout=settings.SMALL_TIMEOUT):
812
832
self .__slow_mode_pause_if_set ()
813
833
self .loop .run_until_complete (self .page .wait ())
814
834
815
- def set_value (self , selector , text , timeout = settings . SMALL_TIMEOUT ):
835
+ def set_value (self , selector , text , timeout = None ):
816
836
"""Similar to send_keys(), but clears the text field first."""
837
+ if not timeout :
838
+ timeout = settings .SMALL_TIMEOUT
817
839
self .__slow_mode_pause_if_set ()
818
840
selector = self .__convert_to_css_if_xpath (selector )
819
841
element = self .select (selector , timeout = timeout )
@@ -1036,7 +1058,9 @@ def get_window_position(self):
1036
1058
coordinates ["y" ] = y if y else 0
1037
1059
return coordinates
1038
1060
1039
- def get_element_rect (self , selector , timeout = settings .SMALL_TIMEOUT ):
1061
+ def get_element_rect (self , selector , timeout = None ):
1062
+ if not timeout :
1063
+ timeout = settings .SMALL_TIMEOUT
1040
1064
selector = self .__convert_to_css_if_xpath (selector )
1041
1065
self .select (selector , timeout = timeout )
1042
1066
self .__add_light_pause ()
@@ -1049,23 +1073,29 @@ def get_element_rect(self, selector, timeout=settings.SMALL_TIMEOUT):
1049
1073
)
1050
1074
return coordinates
1051
1075
1052
- def get_element_size (self , selector ):
1053
- element_rect = self .get_element_rect (selector )
1076
+ def get_element_size (self , selector , timeout = None ):
1077
+ if not timeout :
1078
+ timeout = settings .SMALL_TIMEOUT
1079
+ element_rect = self .get_element_rect (selector , timeout = timeout )
1054
1080
coordinates = {}
1055
1081
coordinates ["width" ] = element_rect ["width" ]
1056
1082
coordinates ["height" ] = element_rect ["height" ]
1057
1083
return coordinates
1058
1084
1059
- def get_element_position (self , selector ):
1060
- element_rect = self .get_element_rect (selector )
1085
+ def get_element_position (self , selector , timeout = None ):
1086
+ if not timeout :
1087
+ timeout = settings .SMALL_TIMEOUT
1088
+ element_rect = self .get_element_rect (selector , timeout = timeout )
1061
1089
coordinates = {}
1062
1090
coordinates ["x" ] = element_rect ["x" ]
1063
1091
coordinates ["y" ] = element_rect ["y" ]
1064
1092
return coordinates
1065
1093
1066
- def get_gui_element_rect (self , selector ):
1094
+ def get_gui_element_rect (self , selector , timeout = None ):
1067
1095
"""(Coordinates are relative to the screen. Not the window.)"""
1068
- element_rect = self .get_element_rect (selector )
1096
+ if not timeout :
1097
+ timeout = settings .SMALL_TIMEOUT
1098
+ element_rect = self .get_element_rect (selector , timeout = timeout )
1069
1099
e_width = element_rect ["width" ]
1070
1100
e_height = element_rect ["height" ]
1071
1101
window_rect = self .get_window_rect ()
@@ -1079,9 +1109,11 @@ def get_gui_element_rect(self, selector):
1079
1109
y = y + window_rect ["scrollY" ]
1080
1110
return ({"height" : e_height , "width" : e_width , "x" : x , "y" : y })
1081
1111
1082
- def get_gui_element_center (self , selector ):
1112
+ def get_gui_element_center (self , selector , timeout = None ):
1083
1113
"""(Coordinates are relative to the screen. Not the window.)"""
1084
- element_rect = self .get_gui_element_rect (selector )
1114
+ if not timeout :
1115
+ timeout = settings .SMALL_TIMEOUT
1116
+ element_rect = self .get_gui_element_rect (selector , timeout = timeout )
1085
1117
e_width = element_rect ["width" ]
1086
1118
e_height = element_rect ["height" ]
1087
1119
e_x = element_rect ["x" ]
@@ -1629,9 +1661,9 @@ def is_element_visible(self, selector):
1629
1661
return True
1630
1662
return False
1631
1663
1632
- def wait_for_element_visible (
1633
- self , selector , timeout = settings . SMALL_TIMEOUT
1634
- ):
1664
+ def wait_for_element_visible (self , selector , timeout = None ):
1665
+ if not timeout :
1666
+ timeout = settings . SMALL_TIMEOUT
1635
1667
try :
1636
1668
self .select (selector , timeout = timeout )
1637
1669
except Exception :
@@ -1642,8 +1674,10 @@ def wait_for_element_visible(
1642
1674
time .sleep (0.1 )
1643
1675
raise Exception ("Element {%s} was not visible!" % selector )
1644
1676
1645
- def assert_element (self , selector , timeout = settings . SMALL_TIMEOUT ):
1677
+ def assert_element (self , selector , timeout = None ):
1646
1678
"""Same as assert_element_visible()"""
1679
+ if not timeout :
1680
+ timeout = settings .SMALL_TIMEOUT
1647
1681
try :
1648
1682
self .select (selector , timeout = timeout )
1649
1683
except Exception :
@@ -1654,8 +1688,10 @@ def assert_element(self, selector, timeout=settings.SMALL_TIMEOUT):
1654
1688
time .sleep (0.1 )
1655
1689
raise Exception ("Element {%s} was not visible!" % selector )
1656
1690
1657
- def assert_element_visible (self , selector , timeout = settings . SMALL_TIMEOUT ):
1691
+ def assert_element_visible (self , selector , timeout = None ):
1658
1692
"""Same as assert_element()"""
1693
+ if not timeout :
1694
+ timeout = settings .SMALL_TIMEOUT
1659
1695
try :
1660
1696
self .select (selector , timeout = timeout )
1661
1697
except Exception :
@@ -1666,16 +1702,20 @@ def assert_element_visible(self, selector, timeout=settings.SMALL_TIMEOUT):
1666
1702
time .sleep (0.1 )
1667
1703
raise Exception ("Element {%s} was not visible!" % selector )
1668
1704
1669
- def assert_element_present (self , selector , timeout = settings . SMALL_TIMEOUT ):
1705
+ def assert_element_present (self , selector , timeout = None ):
1670
1706
"""Assert element is present in the DOM. (Visibility NOT required)"""
1707
+ if not timeout :
1708
+ timeout = settings .SMALL_TIMEOUT
1671
1709
try :
1672
1710
self .select (selector , timeout = timeout )
1673
1711
except Exception :
1674
1712
raise Exception ("Element {%s} was not found!" % selector )
1675
1713
return True
1676
1714
1677
- def assert_element_absent (self , selector , timeout = settings . SMALL_TIMEOUT ):
1715
+ def assert_element_absent (self , selector , timeout = None ):
1678
1716
"""Assert element is not present in the DOM."""
1717
+ if not timeout :
1718
+ timeout = settings .SMALL_TIMEOUT
1679
1719
start_ms = time .time () * 1000.0
1680
1720
stop_ms = start_ms + (timeout * 1000.0 )
1681
1721
for i in range (int (timeout * 10 )):
@@ -1693,10 +1733,10 @@ def assert_element_absent(self, selector, timeout=settings.SMALL_TIMEOUT):
1693
1733
% (selector , timeout , plural )
1694
1734
)
1695
1735
1696
- def assert_element_not_visible (
1697
- self , selector , timeout = settings .SMALL_TIMEOUT
1698
- ):
1736
+ def assert_element_not_visible (self , selector , timeout = None ):
1699
1737
"""Assert element is not visible on page. (May still be in DOM)"""
1738
+ if not timeout :
1739
+ timeout = settings .SMALL_TIMEOUT
1700
1740
start_ms = time .time () * 1000.0
1701
1741
stop_ms = start_ms + (timeout * 1000.0 )
1702
1742
for i in range (int (timeout * 10 )):
@@ -1791,9 +1831,9 @@ def assert_url_contains(self, substring):
1791
1831
if expected not in actual :
1792
1832
raise Exception (error % (expected , actual ))
1793
1833
1794
- def assert_text (
1795
- self , text , selector = "body" , timeout = settings . SMALL_TIMEOUT
1796
- ):
1834
+ def assert_text (self , text , selector = "body" , timeout = None ):
1835
+ if not timeout :
1836
+ timeout = settings . SMALL_TIMEOUT
1797
1837
start_ms = time .time () * 1000.0
1798
1838
stop_ms = start_ms + (timeout * 1000.0 )
1799
1839
text = text .strip ()
@@ -1816,9 +1856,9 @@ def assert_text(
1816
1856
% (text , selector , element .text_all )
1817
1857
)
1818
1858
1819
- def assert_exact_text (
1820
- self , text , selector = "body" , timeout = settings . SMALL_TIMEOUT
1821
- ):
1859
+ def assert_exact_text (self , text , selector = "body" , timeout = None ):
1860
+ if not timeout :
1861
+ timeout = settings . SMALL_TIMEOUT
1822
1862
start_ms = time .time () * 1000.0
1823
1863
stop_ms = start_ms + (timeout * 1000.0 )
1824
1864
text = text .strip ()
0 commit comments