Skip to content

Commit ef9e3e5

Browse files
authored
Merge pull request #230 from seleniumbase/method-updates
Method updates
2 parents 2200fc2 + 19b350c commit ef9e3e5

File tree

3 files changed

+115
-58
lines changed

3 files changed

+115
-58
lines changed

help_docs/method_summary.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ self.is_partial_link_text_visible(partial_link_text)
7171

7272
self.is_text_visible(text, selector, by=By.CSS_SELECTOR)
7373

74+
self.find_elements(selector, by=By.CSS_SELECTOR)
75+
7476
self.find_visible_elements(selector, by=By.CSS_SELECTOR)
7577

7678
self.is_element_in_an_iframe(selector, by=By.CSS_SELECTOR)
@@ -194,13 +196,13 @@ self.hover_and_click(hover_selector, click_selector,
194196
hover_by=By.CSS_SELECTOR, click_by=By.CSS_SELECTOR,
195197
timeout=settings.SMALL_TIMEOUT)
196198

197-
self.pick_select_option_by_text(dropdown_selector, option,
199+
self.select_option_by_text(dropdown_selector, option,
198200
dropdown_by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
199201

200-
self.pick_select_option_by_index(dropdown_selector, option,
202+
self.select_option_by_index(dropdown_selector, option,
201203
dropdown_by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
202204

203-
self.pick_select_option_by_value(dropdown_selector, option,
205+
self.select_option_by_value(dropdown_selector, option,
204206
dropdown_by=By.CSS_SELECTOR, timeout=settings.SMALL_TIMEOUT)
205207

206208
########

seleniumbase/fixtures/base_case.py

Lines changed: 109 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,19 @@ def is_text_visible(self, text, selector, by=By.CSS_SELECTOR):
643643
by = By.LINK_TEXT
644644
return page_actions.is_text_visible(self.driver, text, selector, by)
645645

646+
def find_elements(self, selector, by=By.CSS_SELECTOR):
647+
""" Returns a list of matching WebElements. """
648+
self.wait_for_ready_state_complete()
649+
if page_utils.is_xpath_selector(selector):
650+
by = By.XPATH
651+
if page_utils.is_link_text_selector(selector):
652+
selector = page_utils.get_link_text_from_selector(selector)
653+
by = By.LINK_TEXT
654+
return self.driver.find_elements(by=by, value=selector)
655+
646656
def find_visible_elements(self, selector, by=By.CSS_SELECTOR):
647657
""" Returns a list of matching WebElements that are visible. """
658+
self.wait_for_ready_state_complete()
648659
if page_utils.is_xpath_selector(selector):
649660
by = By.XPATH
650661
if page_utils.is_link_text_selector(selector):
@@ -1648,35 +1659,115 @@ def hover_and_click(self, hover_selector, click_selector,
16481659
self.__demo_mode_pause_if_active(tiny=True)
16491660
return element
16501661

1662+
def __select_option(self, dropdown_selector, option,
1663+
dropdown_by=By.CSS_SELECTOR, option_by="text",
1664+
timeout=settings.SMALL_TIMEOUT):
1665+
""" Selects an HTML <select> option by specification.
1666+
Option specifications are by "text", "index", or "value".
1667+
Defaults to "text" if option_by is unspecified or unknown. """
1668+
if page_utils.is_xpath_selector(dropdown_selector):
1669+
dropdown_by = By.XPATH
1670+
element = self.find_element(
1671+
dropdown_selector, by=dropdown_by, timeout=timeout)
1672+
self.__demo_mode_highlight_if_active(dropdown_selector, dropdown_by)
1673+
pre_action_url = self.driver.current_url
1674+
try:
1675+
if option_by == "index":
1676+
Select(element).select_by_index(option)
1677+
elif option_by == "value":
1678+
Select(element).select_by_value(option)
1679+
else:
1680+
Select(element).select_by_visible_text(option)
1681+
except (StaleElementReferenceException, ENI_Exception):
1682+
self.wait_for_ready_state_complete()
1683+
time.sleep(0.05)
1684+
element = self.find_element(
1685+
dropdown_selector, by=dropdown_by, timeout=timeout)
1686+
if option_by == "index":
1687+
Select(element).select_by_index(option)
1688+
elif option_by == "value":
1689+
Select(element).select_by_value(option)
1690+
else:
1691+
Select(element).select_by_visible_text(option)
1692+
if settings.WAIT_FOR_RSC_ON_CLICKS:
1693+
self.wait_for_ready_state_complete()
1694+
if self.demo_mode:
1695+
if self.driver.current_url != pre_action_url:
1696+
self.__demo_mode_pause_if_active()
1697+
else:
1698+
self.__demo_mode_pause_if_active(tiny=True)
1699+
1700+
def select_option_by_text(self, dropdown_selector, option,
1701+
dropdown_by=By.CSS_SELECTOR,
1702+
timeout=settings.SMALL_TIMEOUT):
1703+
""" Selects an HTML <select> option by option text.
1704+
@Params
1705+
dropdown_selector - the <select> selector
1706+
option - the text of the option """
1707+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1708+
timeout = self.__get_new_timeout(timeout)
1709+
self.__select_option(dropdown_selector, option,
1710+
dropdown_by=dropdown_by, option_by="text",
1711+
timeout=timeout)
1712+
1713+
def select_option_by_index(self, dropdown_selector, option,
1714+
dropdown_by=By.CSS_SELECTOR,
1715+
timeout=settings.SMALL_TIMEOUT):
1716+
""" Selects an HTML <select> option by option index.
1717+
@Params
1718+
dropdown_selector - the <select> selector
1719+
option - the index number of the option """
1720+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1721+
timeout = self.__get_new_timeout(timeout)
1722+
self.__select_option(dropdown_selector, option,
1723+
dropdown_by=dropdown_by, option_by="index",
1724+
timeout=timeout)
1725+
1726+
def select_option_by_value(self, dropdown_selector, option,
1727+
dropdown_by=By.CSS_SELECTOR,
1728+
timeout=settings.SMALL_TIMEOUT):
1729+
""" Selects an HTML <select> option by option value.
1730+
@Params
1731+
dropdown_selector - the <select> selector
1732+
option - the value property of the option """
1733+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
1734+
timeout = self.__get_new_timeout(timeout)
1735+
self.__select_option(dropdown_selector, option,
1736+
dropdown_by=dropdown_by, option_by="value",
1737+
timeout=timeout)
1738+
1739+
@decorators.deprecated("Use self.select_option_by_text() instead!")
16511740
def pick_select_option_by_text(self, dropdown_selector, option,
16521741
dropdown_by=By.CSS_SELECTOR,
1653-
timeout=settings.LARGE_TIMEOUT):
1654-
""" Picks an HTML <select> option by option text. """
1655-
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
1742+
timeout=settings.SMALL_TIMEOUT):
1743+
""" Selects an HTML <select> option by option text. """
1744+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
16561745
timeout = self.__get_new_timeout(timeout)
1657-
self.__pick_select_option(dropdown_selector, option,
1658-
dropdown_by=dropdown_by, option_by="text",
1659-
timeout=timeout)
1746+
self.__select_option(dropdown_selector, option,
1747+
dropdown_by=dropdown_by, option_by="text",
1748+
timeout=timeout)
16601749

1750+
@decorators.deprecated("Use self.select_option_by_index() instead!")
16611751
def pick_select_option_by_index(self, dropdown_selector, option,
16621752
dropdown_by=By.CSS_SELECTOR,
1663-
timeout=settings.LARGE_TIMEOUT):
1664-
""" Picks an HTML <select> option by option index. """
1665-
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
1753+
timeout=settings.SMALL_TIMEOUT):
1754+
""" Selects an HTML <select> option by option index. """
1755+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
16661756
timeout = self.__get_new_timeout(timeout)
1667-
self.__pick_select_option(dropdown_selector, option,
1668-
dropdown_by=dropdown_by, option_by="index",
1669-
timeout=timeout)
1757+
self.__select_option(dropdown_selector, option,
1758+
dropdown_by=dropdown_by, option_by="index",
1759+
timeout=timeout)
16701760

1761+
@decorators.deprecated("Use self.select_option_by_value() instead!")
16711762
def pick_select_option_by_value(self, dropdown_selector, option,
16721763
dropdown_by=By.CSS_SELECTOR,
1673-
timeout=settings.LARGE_TIMEOUT):
1674-
""" Picks an HTML <select> option by option value. """
1675-
if self.timeout_multiplier and timeout == settings.LARGE_TIMEOUT:
1764+
timeout=settings.SMALL_TIMEOUT):
1765+
""" Selects an HTML <select> option by option value. """
1766+
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
16761767
timeout = self.__get_new_timeout(timeout)
1677-
self.__pick_select_option(dropdown_selector, option,
1678-
dropdown_by=dropdown_by, option_by="value",
1679-
timeout=timeout)
1768+
self.__select_option(dropdown_selector, option,
1769+
dropdown_by=dropdown_by, option_by="value",
1770+
timeout=timeout)
16801771

16811772
############
16821773

@@ -2360,42 +2451,6 @@ def __click_dropdown_link_text(self, link_text, link_css):
23602451
pass
23612452
return False
23622453

2363-
def __pick_select_option(self, dropdown_selector, option,
2364-
dropdown_by=By.CSS_SELECTOR, option_by="text",
2365-
timeout=settings.SMALL_TIMEOUT):
2366-
""" Picks an HTML <select> option by specification.
2367-
Option specifications are by "text", "index", or "value".
2368-
Defaults to "text" if option_by is unspecified or unknown. """
2369-
element = self.find_element(
2370-
dropdown_selector, by=dropdown_by, timeout=timeout)
2371-
self.__demo_mode_highlight_if_active(dropdown_selector, dropdown_by)
2372-
pre_action_url = self.driver.current_url
2373-
try:
2374-
if option_by == "index":
2375-
Select(element).select_by_index(option)
2376-
elif option_by == "value":
2377-
Select(element).select_by_value(option)
2378-
else:
2379-
Select(element).select_by_visible_text(option)
2380-
except (StaleElementReferenceException, ENI_Exception):
2381-
self.wait_for_ready_state_complete()
2382-
time.sleep(0.05)
2383-
element = self.find_element(
2384-
dropdown_selector, by=dropdown_by, timeout=timeout)
2385-
if option_by == "index":
2386-
Select(element).select_by_index(option)
2387-
elif option_by == "value":
2388-
Select(element).select_by_value(option)
2389-
else:
2390-
Select(element).select_by_visible_text(option)
2391-
if settings.WAIT_FOR_RSC_ON_CLICKS:
2392-
self.wait_for_ready_state_complete()
2393-
if self.demo_mode:
2394-
if self.driver.current_url != pre_action_url:
2395-
self.__demo_mode_pause_if_active()
2396-
else:
2397-
self.__demo_mode_pause_if_active(tiny=True)
2398-
23992454
def __recalculate_selector(self, selector, by):
24002455
# Try to determine the type of selector automatically
24012456
if page_utils.is_xpath_selector(selector):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.16.12',
20+
version='1.16.13',
2121
description='All-In-One Test Automation Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)