@@ -669,6 +669,7 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
669
669
(Default: 4. Each loop lasts for about 0.18s)
670
670
scroll - the option to scroll to the element first (Default: True)
671
671
"""
672
+ selector , by = self ._recalculate_selector (selector , by )
672
673
element = self .find_element (
673
674
selector , by = by , timeout = settings .SMALL_TIMEOUT )
674
675
if scroll :
@@ -678,11 +679,7 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
678
679
except Exception :
679
680
# Don't highlight if can't convert to CSS_SELECTOR for jQuery
680
681
return
681
-
682
- # Only get the first match
683
- last_syllable = selector .split (' ' )[- 1 ]
684
- if ':' not in last_syllable :
685
- selector += ':first'
682
+ selector = self ._make_css_match_first_element_only (selector )
686
683
687
684
o_bs = '' # original_box_shadow
688
685
style = element .get_attribute ('style' )
@@ -695,11 +692,8 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
695
692
696
693
script = """jQuery('%s').css('box-shadow',
697
694
'0px 0px 6px 6px rgba(128, 128, 128, 0.5)');""" % selector
698
- try :
699
- self .execute_script (script )
700
- except Exception :
701
- self .activate_jquery ()
702
- self .execute_script (script )
695
+ self .safe_execute_script (script )
696
+
703
697
if self .highlights :
704
698
loops = self .highlights
705
699
loops = int (loops )
@@ -869,19 +863,9 @@ def set_value(self, selector, new_value, by=By.CSS_SELECTOR,
869
863
self ._demo_mode_highlight_if_active (selector , by )
870
864
self .scroll_to (selector , by = by , timeout = timeout )
871
865
value = json .dumps (new_value )
872
-
873
- # Only get the first match
874
- last_syllable = selector .split (' ' )[- 1 ]
875
- if ':' not in last_syllable :
876
- selector += ':first'
877
-
866
+ selector = self ._make_css_match_first_element_only (selector )
878
867
set_value_script = """jQuery('%s').val(%s)""" % (selector , value )
879
- try :
880
- self .execute_script (set_value_script )
881
- except Exception :
882
- # The likely reason this fails is because: "jQuery is not defined"
883
- self .activate_jquery () # It's a good thing we can define it here
884
- self .execute_script (set_value_script )
868
+ self .safe_execute_script (set_value_script )
885
869
self ._demo_mode_pause_if_active ()
886
870
887
871
def jquery_update_text_value (self , selector , new_value , by = By .CSS_SELECTOR ,
@@ -899,20 +883,10 @@ def jquery_update_text_value(self, selector, new_value, by=By.CSS_SELECTOR,
899
883
self ._demo_mode_highlight_if_active (selector , by )
900
884
self .scroll_to (selector , by = by )
901
885
selector = self .convert_to_css_selector (selector , by = by )
902
-
903
- # Only get the first match
904
- last_syllable = selector .split (' ' )[- 1 ]
905
- if ':' not in last_syllable :
906
- selector += ':first'
907
-
886
+ selector = self ._make_css_match_first_element_only (selector )
908
887
update_text_script = """jQuery('%s').val('%s')""" % (
909
888
selector , self .jq_format (new_value ))
910
- try :
911
- self .execute_script (update_text_script )
912
- except Exception :
913
- # The likely reason this fails is because: "jQuery is not defined"
914
- self .activate_jquery () # It's a good thing we can define it here
915
- self .execute_script (update_text_script )
889
+ self .safe_execute_script (update_text_script )
916
890
if new_value .endswith ('\n ' ):
917
891
element .send_keys ('\n ' )
918
892
self ._demo_mode_pause_if_active ()
0 commit comments