@@ -643,8 +643,19 @@ def is_text_visible(self, text, selector, by=By.CSS_SELECTOR):
643
643
by = By .LINK_TEXT
644
644
return page_actions .is_text_visible (self .driver , text , selector , by )
645
645
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
+
646
656
def find_visible_elements (self , selector , by = By .CSS_SELECTOR ):
647
657
""" Returns a list of matching WebElements that are visible. """
658
+ self .wait_for_ready_state_complete ()
648
659
if page_utils .is_xpath_selector (selector ):
649
660
by = By .XPATH
650
661
if page_utils .is_link_text_selector (selector ):
@@ -1648,35 +1659,115 @@ def hover_and_click(self, hover_selector, click_selector,
1648
1659
self .__demo_mode_pause_if_active (tiny = True )
1649
1660
return element
1650
1661
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!" )
1651
1740
def pick_select_option_by_text (self , dropdown_selector , option ,
1652
1741
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 :
1656
1745
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 )
1660
1749
1750
+ @decorators .deprecated ("Use self.select_option_by_index() instead!" )
1661
1751
def pick_select_option_by_index (self , dropdown_selector , option ,
1662
1752
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 :
1666
1756
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 )
1670
1760
1761
+ @decorators .deprecated ("Use self.select_option_by_value() instead!" )
1671
1762
def pick_select_option_by_value (self , dropdown_selector , option ,
1672
1763
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 :
1676
1767
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 )
1680
1771
1681
1772
############
1682
1773
@@ -2360,42 +2451,6 @@ def __click_dropdown_link_text(self, link_text, link_css):
2360
2451
pass
2361
2452
return False
2362
2453
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
-
2399
2454
def __recalculate_selector (self , selector , by ):
2400
2455
# Try to determine the type of selector automatically
2401
2456
if page_utils .is_xpath_selector (selector ):
0 commit comments