@@ -200,8 +200,7 @@ def double_click(self, selector, by=By.CSS_SELECTOR, timeout=None):
200
200
timeout = settings .SMALL_TIMEOUT
201
201
if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
202
202
timeout = self .__get_new_timeout (timeout )
203
- if page_utils .is_xpath_selector (selector ):
204
- by = By .XPATH
203
+ selector , by = self .__recalculate_selector (selector , by )
205
204
element = page_actions .wait_for_element_visible (
206
205
self .driver , selector , by , timeout = timeout )
207
206
self .__demo_mode_highlight_if_active (selector , by )
@@ -265,8 +264,7 @@ def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
265
264
timeout = settings .LARGE_TIMEOUT
266
265
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
267
266
timeout = self .__get_new_timeout (timeout )
268
- if page_utils .is_xpath_selector (selector ):
269
- by = By .XPATH
267
+ selector , by = self .__recalculate_selector (selector , by )
270
268
element = self .wait_for_element_visible (
271
269
selector , by = by , timeout = timeout )
272
270
self .__demo_mode_highlight_if_active (selector , by )
@@ -336,8 +334,7 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
336
334
timeout = settings .LARGE_TIMEOUT
337
335
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
338
336
timeout = self .__get_new_timeout (timeout )
339
- if page_utils .is_xpath_selector (selector ):
340
- by = By .XPATH
337
+ selector , by = self .__recalculate_selector (selector , by )
341
338
element = self .wait_for_element_visible (
342
339
selector , by = by , timeout = timeout )
343
340
self .__demo_mode_highlight_if_active (selector , by )
@@ -379,8 +376,7 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
379
376
380
377
def submit (self , selector , by = By .CSS_SELECTOR ):
381
378
""" Alternative to self.driver.find_element_by_*(SELECTOR).submit() """
382
- if page_utils .is_xpath_selector (selector ):
383
- by = By .XPATH
379
+ selector , by = self .__recalculate_selector (selector , by )
384
380
element = self .wait_for_element_visible (
385
381
selector , by = by , timeout = settings .SMALL_TIMEOUT )
386
382
element .submit ()
@@ -733,8 +729,7 @@ def get_text(self, selector, by=By.CSS_SELECTOR, timeout=None):
733
729
timeout = settings .SMALL_TIMEOUT
734
730
if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
735
731
timeout = self .__get_new_timeout (timeout )
736
- if page_utils .is_xpath_selector (selector ):
737
- by = By .XPATH
732
+ selector , by = self .__recalculate_selector (selector , by )
738
733
self .wait_for_ready_state_complete ()
739
734
time .sleep (0.01 )
740
735
element = page_actions .wait_for_element_visible (
@@ -1857,8 +1852,7 @@ def bring_to_front(self, selector, by=By.CSS_SELECTOR):
1857
1852
Useful when getting a WebDriverException, such as the one below:
1858
1853
{ Element is not clickable at point (#, #).
1859
1854
Other element would receive the click: ... } """
1860
- if page_utils .is_xpath_selector (selector ):
1861
- by = By .XPATH
1855
+ selector , by = self .__recalculate_selector (selector , by )
1862
1856
self .wait_for_element_visible (
1863
1857
selector , by = by , timeout = settings .SMALL_TIMEOUT )
1864
1858
try :
@@ -2444,8 +2438,7 @@ def choose_file(self, selector, file_path, by=By.CSS_SELECTOR,
2444
2438
timeout = settings .LARGE_TIMEOUT
2445
2439
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2446
2440
timeout = self .__get_new_timeout (timeout )
2447
- if page_utils .is_xpath_selector (selector ):
2448
- by = By .XPATH
2441
+ selector , by = self .__recalculate_selector (selector , by )
2449
2442
abs_path = os .path .abspath (file_path )
2450
2443
self .add_text (selector , abs_path , by = by , timeout = timeout )
2451
2444
@@ -2724,8 +2717,7 @@ def set_value(self, selector, new_value, by=By.CSS_SELECTOR, timeout=None):
2724
2717
timeout = settings .LARGE_TIMEOUT
2725
2718
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2726
2719
timeout = self .__get_new_timeout (timeout )
2727
- if page_utils .is_xpath_selector (selector ):
2728
- by = By .XPATH
2720
+ selector , by = self .__recalculate_selector (selector , by )
2729
2721
orginal_selector = selector
2730
2722
css_selector = self .convert_to_css_selector (selector , by = by )
2731
2723
self .__demo_mode_highlight_if_active (orginal_selector , by )
@@ -2766,8 +2758,7 @@ def jquery_update_text(self, selector, new_value, by=By.CSS_SELECTOR,
2766
2758
timeout = settings .LARGE_TIMEOUT
2767
2759
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2768
2760
timeout = self .__get_new_timeout (timeout )
2769
- if page_utils .is_xpath_selector (selector ):
2770
- by = By .XPATH
2761
+ selector , by = self .__recalculate_selector (selector , by )
2771
2762
element = self .wait_for_element_visible (
2772
2763
selector , by = by , timeout = timeout )
2773
2764
self .__demo_mode_highlight_if_active (selector , by )
@@ -2899,8 +2890,7 @@ def type(self, selector, text, by=By.CSS_SELECTOR,
2899
2890
timeout = settings .LARGE_TIMEOUT
2900
2891
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2901
2892
timeout = self .__get_new_timeout (timeout )
2902
- if page_utils .is_xpath_selector (selector ):
2903
- by = By .XPATH
2893
+ selector , by = self .__recalculate_selector (selector , by )
2904
2894
self .update_text (selector , text , by = by , timeout = timeout , retry = retry )
2905
2895
2906
2896
def input (self , selector , text , by = By .CSS_SELECTOR ,
@@ -2910,8 +2900,7 @@ def input(self, selector, text, by=By.CSS_SELECTOR,
2910
2900
timeout = settings .LARGE_TIMEOUT
2911
2901
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2912
2902
timeout = self .__get_new_timeout (timeout )
2913
- if page_utils .is_xpath_selector (selector ):
2914
- by = By .XPATH
2903
+ selector , by = self .__recalculate_selector (selector , by )
2915
2904
self .update_text (selector , text , by = by , timeout = timeout , retry = retry )
2916
2905
2917
2906
def write (self , selector , text , by = By .CSS_SELECTOR ,
@@ -2921,8 +2910,7 @@ def write(self, selector, text, by=By.CSS_SELECTOR,
2921
2910
timeout = settings .LARGE_TIMEOUT
2922
2911
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2923
2912
timeout = self .__get_new_timeout (timeout )
2924
- if page_utils .is_xpath_selector (selector ):
2925
- by = By .XPATH
2913
+ selector , by = self .__recalculate_selector (selector , by )
2926
2914
self .update_text (selector , text , by = by , timeout = timeout , retry = retry )
2927
2915
2928
2916
def send_keys (self , selector , text , by = By .CSS_SELECTOR , timeout = None ):
@@ -2931,8 +2919,7 @@ def send_keys(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
2931
2919
timeout = settings .LARGE_TIMEOUT
2932
2920
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2933
2921
timeout = self .__get_new_timeout (timeout )
2934
- if page_utils .is_xpath_selector (selector ):
2935
- by = By .XPATH
2922
+ selector , by = self .__recalculate_selector (selector , by )
2936
2923
self .add_text (selector , text , by = by , timeout = timeout )
2937
2924
2938
2925
def click_link (self , link_text , timeout = None ):
@@ -2954,6 +2941,37 @@ def wait_for_element_visible(self, selector, by=By.CSS_SELECTOR,
2954
2941
return page_actions .wait_for_element_visible (
2955
2942
self .driver , selector , by , timeout )
2956
2943
2944
+ def wait_for_element_not_present (self , selector , by = By .CSS_SELECTOR ,
2945
+ timeout = None ):
2946
+ """ Same as self.wait_for_element_absent()
2947
+ Waits for an element to no longer appear in the HTML of a page.
2948
+ A hidden element still counts as appearing in the page HTML.
2949
+ If an element with "hidden" status is acceptable,
2950
+ use wait_for_element_not_visible() instead. """
2951
+ if not timeout :
2952
+ timeout = settings .LARGE_TIMEOUT
2953
+ if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
2954
+ timeout = self .__get_new_timeout (timeout )
2955
+ selector , by = self .__recalculate_selector (selector , by )
2956
+ return page_actions .wait_for_element_absent (
2957
+ self .driver , selector , by , timeout )
2958
+
2959
+ def assert_element_not_present (self , selector , by = By .CSS_SELECTOR ,
2960
+ timeout = None ):
2961
+ """ Same as self.assert_element_absent()
2962
+ Will raise an exception if the element stays present.
2963
+ Returns True if successful. Default timeout = SMALL_TIMEOUT. """
2964
+ if not timeout :
2965
+ timeout = settings .SMALL_TIMEOUT
2966
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
2967
+ timeout = self .__get_new_timeout (timeout )
2968
+ self .wait_for_element_absent (selector , by = by , timeout = timeout )
2969
+ return True
2970
+
2971
+ def wait (self , seconds ):
2972
+ """ Same as sleep() - Some JS frameworks use this method name. """
2973
+ self .sleep (seconds )
2974
+
2957
2975
def _print (self , msg ):
2958
2976
print (msg )
2959
2977
@@ -3161,6 +3179,9 @@ def add_tour_step(self, message, selector=None, name=None,
3161
3179
"""
3162
3180
if not selector :
3163
3181
selector = "html"
3182
+ if page_utils .is_name_selector (selector ):
3183
+ name = page_utils .get_name_from_selector (selector )
3184
+ selector = '[name="%s"]' % name
3164
3185
if page_utils .is_xpath_selector (selector ):
3165
3186
selector = self .convert_to_css_selector (selector , By .XPATH )
3166
3187
selector = self .__escape_quotes_if_needed (selector )
@@ -3860,8 +3881,7 @@ def wait_for_element_absent(self, selector, by=By.CSS_SELECTOR,
3860
3881
timeout = settings .LARGE_TIMEOUT
3861
3882
if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
3862
3883
timeout = self .__get_new_timeout (timeout )
3863
- if page_utils .is_xpath_selector (selector ):
3864
- by = By .XPATH
3884
+ selector , by = self .__recalculate_selector (selector , by )
3865
3885
return page_actions .wait_for_element_absent (
3866
3886
self .driver , selector , by , timeout )
3867
3887
0 commit comments