Skip to content

Commit 7956808

Browse files
committed
Use the reusable methods.
1 parent 1707ddf commit 7956808

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
669669
(Default: 4. Each loop lasts for about 0.18s)
670670
scroll - the option to scroll to the element first (Default: True)
671671
"""
672+
selector, by = self._recalculate_selector(selector, by)
672673
element = self.find_element(
673674
selector, by=by, timeout=settings.SMALL_TIMEOUT)
674675
if scroll:
@@ -678,11 +679,7 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
678679
except Exception:
679680
# Don't highlight if can't convert to CSS_SELECTOR for jQuery
680681
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)
686683

687684
o_bs = '' # original_box_shadow
688685
style = element.get_attribute('style')
@@ -695,11 +692,8 @@ def highlight(self, selector, by=By.CSS_SELECTOR,
695692

696693
script = """jQuery('%s').css('box-shadow',
697694
'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+
703697
if self.highlights:
704698
loops = self.highlights
705699
loops = int(loops)
@@ -869,19 +863,9 @@ def set_value(self, selector, new_value, by=By.CSS_SELECTOR,
869863
self._demo_mode_highlight_if_active(selector, by)
870864
self.scroll_to(selector, by=by, timeout=timeout)
871865
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)
878867
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)
885869
self._demo_mode_pause_if_active()
886870

887871
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,
899883
self._demo_mode_highlight_if_active(selector, by)
900884
self.scroll_to(selector, by=by)
901885
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)
908887
update_text_script = """jQuery('%s').val('%s')""" % (
909888
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)
916890
if new_value.endswith('\n'):
917891
element.send_keys('\n')
918892
self._demo_mode_pause_if_active()

0 commit comments

Comments
 (0)