Skip to content

Commit 8abf98b

Browse files
committed
Refactoring
1 parent 4353637 commit 8abf98b

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

seleniumbase/common/encryption.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def blend_strings(string1, string2):
7171
return new_string
7272

7373

74-
def rotate(l, n):
75-
return l[n:] + l[:n]
74+
def rotate(string, n):
75+
return string[n:] + string[:n]
7676

7777

7878
def ord_string_sum(string):

seleniumbase/fixtures/base_case.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ def double_click(self, selector, by=By.CSS_SELECTOR, timeout=None):
200200
timeout = settings.SMALL_TIMEOUT
201201
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
202202
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)
205204
element = page_actions.wait_for_element_visible(
206205
self.driver, selector, by, timeout=timeout)
207206
self.__demo_mode_highlight_if_active(selector, by)
@@ -265,8 +264,7 @@ def update_text(self, selector, new_value, by=By.CSS_SELECTOR,
265264
timeout = settings.LARGE_TIMEOUT
266265
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
267266
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)
270268
element = self.wait_for_element_visible(
271269
selector, by=by, timeout=timeout)
272270
self.__demo_mode_highlight_if_active(selector, by)
@@ -336,8 +334,7 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
336334
timeout = settings.LARGE_TIMEOUT
337335
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
338336
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)
341338
element = self.wait_for_element_visible(
342339
selector, by=by, timeout=timeout)
343340
self.__demo_mode_highlight_if_active(selector, by)
@@ -379,8 +376,7 @@ def add_text(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
379376

380377
def submit(self, selector, by=By.CSS_SELECTOR):
381378
""" 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)
384380
element = self.wait_for_element_visible(
385381
selector, by=by, timeout=settings.SMALL_TIMEOUT)
386382
element.submit()
@@ -733,8 +729,7 @@ def get_text(self, selector, by=By.CSS_SELECTOR, timeout=None):
733729
timeout = settings.SMALL_TIMEOUT
734730
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
735731
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)
738733
self.wait_for_ready_state_complete()
739734
time.sleep(0.01)
740735
element = page_actions.wait_for_element_visible(
@@ -1857,8 +1852,7 @@ def bring_to_front(self, selector, by=By.CSS_SELECTOR):
18571852
Useful when getting a WebDriverException, such as the one below:
18581853
{ Element is not clickable at point (#, #).
18591854
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)
18621856
self.wait_for_element_visible(
18631857
selector, by=by, timeout=settings.SMALL_TIMEOUT)
18641858
try:
@@ -2444,8 +2438,7 @@ def choose_file(self, selector, file_path, by=By.CSS_SELECTOR,
24442438
timeout = settings.LARGE_TIMEOUT
24452439
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
24462440
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)
24492442
abs_path = os.path.abspath(file_path)
24502443
self.add_text(selector, abs_path, by=by, timeout=timeout)
24512444

@@ -2724,8 +2717,7 @@ def set_value(self, selector, new_value, by=By.CSS_SELECTOR, timeout=None):
27242717
timeout = settings.LARGE_TIMEOUT
27252718
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
27262719
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)
27292721
orginal_selector = selector
27302722
css_selector = self.convert_to_css_selector(selector, by=by)
27312723
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,
27662758
timeout = settings.LARGE_TIMEOUT
27672759
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
27682760
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)
27712762
element = self.wait_for_element_visible(
27722763
selector, by=by, timeout=timeout)
27732764
self.__demo_mode_highlight_if_active(selector, by)
@@ -2899,8 +2890,7 @@ def type(self, selector, text, by=By.CSS_SELECTOR,
28992890
timeout = settings.LARGE_TIMEOUT
29002891
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
29012892
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)
29042894
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
29052895

29062896
def input(self, selector, text, by=By.CSS_SELECTOR,
@@ -2910,8 +2900,7 @@ def input(self, selector, text, by=By.CSS_SELECTOR,
29102900
timeout = settings.LARGE_TIMEOUT
29112901
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
29122902
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)
29152904
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
29162905

29172906
def write(self, selector, text, by=By.CSS_SELECTOR,
@@ -2921,8 +2910,7 @@ def write(self, selector, text, by=By.CSS_SELECTOR,
29212910
timeout = settings.LARGE_TIMEOUT
29222911
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
29232912
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)
29262914
self.update_text(selector, text, by=by, timeout=timeout, retry=retry)
29272915

29282916
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):
29312919
timeout = settings.LARGE_TIMEOUT
29322920
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
29332921
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)
29362923
self.add_text(selector, text, by=by, timeout=timeout)
29372924

29382925
def click_link(self, link_text, timeout=None):
@@ -3161,6 +3148,9 @@ def add_tour_step(self, message, selector=None, name=None,
31613148
"""
31623149
if not selector:
31633150
selector = "html"
3151+
if page_utils.is_name_selector(selector):
3152+
name = page_utils.get_name_from_selector(selector)
3153+
selector = '[name="%s"]' % name
31643154
if page_utils.is_xpath_selector(selector):
31653155
selector = self.convert_to_css_selector(selector, By.XPATH)
31663156
selector = self.__escape_quotes_if_needed(selector)
@@ -3860,8 +3850,7 @@ def wait_for_element_absent(self, selector, by=By.CSS_SELECTOR,
38603850
timeout = settings.LARGE_TIMEOUT
38613851
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
38623852
timeout = self.__get_new_timeout(timeout)
3863-
if page_utils.is_xpath_selector(selector):
3864-
by = By.XPATH
3853+
selector, by = self.__recalculate_selector(selector, by)
38653854
return page_actions.wait_for_element_absent(
38663855
self.driver, selector, by, timeout)
38673856

0 commit comments

Comments
 (0)