@@ -1648,35 +1648,115 @@ def hover_and_click(self, hover_selector, click_selector,
1648
1648
self .__demo_mode_pause_if_active (tiny = True )
1649
1649
return element
1650
1650
1651
+ def __select_option (self , dropdown_selector , option ,
1652
+ dropdown_by = By .CSS_SELECTOR , option_by = "text" ,
1653
+ timeout = settings .SMALL_TIMEOUT ):
1654
+ """ Selects an HTML <select> option by specification.
1655
+ Option specifications are by "text", "index", or "value".
1656
+ Defaults to "text" if option_by is unspecified or unknown. """
1657
+ if page_utils .is_xpath_selector (dropdown_selector ):
1658
+ dropdown_by = By .XPATH
1659
+ element = self .find_element (
1660
+ dropdown_selector , by = dropdown_by , timeout = timeout )
1661
+ self .__demo_mode_highlight_if_active (dropdown_selector , dropdown_by )
1662
+ pre_action_url = self .driver .current_url
1663
+ try :
1664
+ if option_by == "index" :
1665
+ Select (element ).select_by_index (option )
1666
+ elif option_by == "value" :
1667
+ Select (element ).select_by_value (option )
1668
+ else :
1669
+ Select (element ).select_by_visible_text (option )
1670
+ except (StaleElementReferenceException , ENI_Exception ):
1671
+ self .wait_for_ready_state_complete ()
1672
+ time .sleep (0.05 )
1673
+ element = self .find_element (
1674
+ dropdown_selector , by = dropdown_by , timeout = timeout )
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
+ if settings .WAIT_FOR_RSC_ON_CLICKS :
1682
+ self .wait_for_ready_state_complete ()
1683
+ if self .demo_mode :
1684
+ if self .driver .current_url != pre_action_url :
1685
+ self .__demo_mode_pause_if_active ()
1686
+ else :
1687
+ self .__demo_mode_pause_if_active (tiny = True )
1688
+
1689
+ def select_option_by_text (self , dropdown_selector , option ,
1690
+ dropdown_by = By .CSS_SELECTOR ,
1691
+ timeout = settings .SMALL_TIMEOUT ):
1692
+ """ Selects an HTML <select> option by option text.
1693
+ @Params
1694
+ dropdown_selector - the <select> selector
1695
+ option - the text of the option """
1696
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1697
+ timeout = self .__get_new_timeout (timeout )
1698
+ self .__select_option (dropdown_selector , option ,
1699
+ dropdown_by = dropdown_by , option_by = "text" ,
1700
+ timeout = timeout )
1701
+
1702
+ def select_option_by_index (self , dropdown_selector , option ,
1703
+ dropdown_by = By .CSS_SELECTOR ,
1704
+ timeout = settings .SMALL_TIMEOUT ):
1705
+ """ Selects an HTML <select> option by option index.
1706
+ @Params
1707
+ dropdown_selector - the <select> selector
1708
+ option - the index number of the option """
1709
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1710
+ timeout = self .__get_new_timeout (timeout )
1711
+ self .__select_option (dropdown_selector , option ,
1712
+ dropdown_by = dropdown_by , option_by = "index" ,
1713
+ timeout = timeout )
1714
+
1715
+ def select_option_by_value (self , dropdown_selector , option ,
1716
+ dropdown_by = By .CSS_SELECTOR ,
1717
+ timeout = settings .SMALL_TIMEOUT ):
1718
+ """ Selects an HTML <select> option by option value.
1719
+ @Params
1720
+ dropdown_selector - the <select> selector
1721
+ option - the value property of the option """
1722
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1723
+ timeout = self .__get_new_timeout (timeout )
1724
+ self .__select_option (dropdown_selector , option ,
1725
+ dropdown_by = dropdown_by , option_by = "value" ,
1726
+ timeout = timeout )
1727
+
1728
+ @decorators .deprecated ("Use self.select_option_by_text() instead!" )
1651
1729
def pick_select_option_by_text (self , dropdown_selector , option ,
1652
1730
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 :
1731
+ timeout = settings .SMALL_TIMEOUT ):
1732
+ """ Selects an HTML <select> option by option text. """
1733
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1656
1734
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 )
1735
+ self .__select_option (dropdown_selector , option ,
1736
+ dropdown_by = dropdown_by , option_by = "text" ,
1737
+ timeout = timeout )
1660
1738
1739
+ @decorators .deprecated ("Use self.select_option_by_index() instead!" )
1661
1740
def pick_select_option_by_index (self , dropdown_selector , option ,
1662
1741
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 :
1742
+ timeout = settings .SMALL_TIMEOUT ):
1743
+ """ Selects an HTML <select> option by option index. """
1744
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1666
1745
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 )
1746
+ self .__select_option (dropdown_selector , option ,
1747
+ dropdown_by = dropdown_by , option_by = "index" ,
1748
+ timeout = timeout )
1670
1749
1750
+ @decorators .deprecated ("Use self.select_option_by_value() instead!" )
1671
1751
def pick_select_option_by_value (self , dropdown_selector , option ,
1672
1752
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 :
1753
+ timeout = settings .SMALL_TIMEOUT ):
1754
+ """ Selects an HTML <select> option by option value. """
1755
+ if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
1676
1756
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 )
1757
+ self .__select_option (dropdown_selector , option ,
1758
+ dropdown_by = dropdown_by , option_by = "value" ,
1759
+ timeout = timeout )
1680
1760
1681
1761
############
1682
1762
@@ -2360,42 +2440,6 @@ def __click_dropdown_link_text(self, link_text, link_css):
2360
2440
pass
2361
2441
return False
2362
2442
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
2443
def __recalculate_selector (self , selector , by ):
2400
2444
# Try to determine the type of selector automatically
2401
2445
if page_utils .is_xpath_selector (selector ):
0 commit comments