@@ -103,15 +103,17 @@ def click(self, selector, by=By.CSS_SELECTOR,
103103 timeout = settings .SMALL_TIMEOUT , delay = 0 ):
104104 if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
105105 timeout = self .__get_new_timeout (timeout )
106- if page_utils .is_xpath_selector (selector ):
107- by = By .XPATH
106+ selector , by = self .__recalculate_selector (selector , by )
108107 if page_utils .is_link_text_selector (selector ):
109- selector = page_utils .get_link_text_from_selector (selector )
110- by = By .LINK_TEXT
111108 if not self .is_link_text_visible (selector ):
112109 # Handle a special case of links hidden in dropdowns
113110 self .click_link_text (selector , timeout = timeout )
114111 return
112+ if page_utils .is_partial_link_text_selector (selector ):
113+ if not self .is_partial_link_text_visible (selector ):
114+ # Handle a special case of partial links hidden in dropdowns
115+ self .click_partial_link_text (selector , timeout = timeout )
116+ return
115117 element = page_actions .wait_for_element_visible (
116118 self .driver , selector , by , timeout = timeout )
117119 self .__demo_mode_highlight_if_active (selector , by )
@@ -427,11 +429,7 @@ def get_attribute(self, selector, attribute, by=By.CSS_SELECTOR,
427429 """ This method uses JavaScript to get the value of an attribute. """
428430 if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
429431 timeout = self .__get_new_timeout (timeout )
430- if page_utils .is_xpath_selector (selector ):
431- by = By .XPATH
432- if page_utils .is_link_text_selector (selector ):
433- selector = page_utils .get_link_text_from_selector (selector )
434- by = By .LINK_TEXT
432+ selector , by = self .__recalculate_selector (selector , by )
435433 self .wait_for_ready_state_complete ()
436434 time .sleep (0.01 )
437435 element = page_actions .wait_for_element_present (
@@ -496,11 +494,7 @@ def get_property_value(self, selector, property, by=By.CSS_SELECTOR,
496494 self.assertTrue(float(opacity) > 0, "Element not visible!") """
497495 if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
498496 timeout = self .__get_new_timeout (timeout )
499- if page_utils .is_xpath_selector (selector ):
500- by = By .XPATH
501- if page_utils .is_link_text_selector (selector ):
502- selector = page_utils .get_link_text_from_selector (selector )
503- by = By .LINK_TEXT
497+ selector , by = self .__recalculate_selector (selector , by )
504498 self .wait_for_ready_state_complete ()
505499 page_actions .wait_for_element_present (
506500 self .driver , selector , by , timeout )
@@ -704,19 +698,11 @@ def type(self, selector, text, by=By.CSS_SELECTOR,
704698 self .update_text (selector , text , by = by , timeout = timeout , retry = retry )
705699
706700 def is_element_present (self , selector , by = By .CSS_SELECTOR ):
707- if page_utils .is_xpath_selector (selector ):
708- by = By .XPATH
709- if page_utils .is_link_text_selector (selector ):
710- selector = page_utils .get_link_text_from_selector (selector )
711- by = By .LINK_TEXT
701+ selector , by = self .__recalculate_selector (selector , by )
712702 return page_actions .is_element_present (self .driver , selector , by )
713703
714704 def is_element_visible (self , selector , by = By .CSS_SELECTOR ):
715- if page_utils .is_xpath_selector (selector ):
716- by = By .XPATH
717- if page_utils .is_link_text_selector (selector ):
718- selector = page_utils .get_link_text_from_selector (selector )
719- by = By .LINK_TEXT
705+ selector , by = self .__recalculate_selector (selector , by )
720706 return page_actions .is_element_visible (self .driver , selector , by )
721707
722708 def is_link_text_visible (self , link_text ):
@@ -734,22 +720,14 @@ def is_partial_link_text_visible(self, partial_link_text):
734720 def is_text_visible (self , text , selector = "html" , by = By .CSS_SELECTOR ):
735721 self .wait_for_ready_state_complete ()
736722 time .sleep (0.01 )
737- if page_utils .is_xpath_selector (selector ):
738- by = By .XPATH
739- if page_utils .is_link_text_selector (selector ):
740- selector = page_utils .get_link_text_from_selector (selector )
741- by = By .LINK_TEXT
723+ selector , by = self .__recalculate_selector (selector , by )
742724 return page_actions .is_text_visible (self .driver , text , selector , by )
743725
744726 def find_elements (self , selector , by = By .CSS_SELECTOR , limit = 0 ):
745727 """ Returns a list of matching WebElements.
746728 If "limit" is set and > 0, will only return that many elements. """
747729 self .wait_for_ready_state_complete ()
748- if page_utils .is_xpath_selector (selector ):
749- by = By .XPATH
750- if page_utils .is_link_text_selector (selector ):
751- selector = page_utils .get_link_text_from_selector (selector )
752- by = By .LINK_TEXT
730+ selector , by = self .__recalculate_selector (selector , by )
753731 elements = self .driver .find_elements (by = by , value = selector )
754732 if limit and limit > 0 and len (elements ) > limit :
755733 elements = elements [:limit ]
@@ -759,11 +737,7 @@ def find_visible_elements(self, selector, by=By.CSS_SELECTOR, limit=0):
759737 """ Returns a list of matching WebElements that are visible.
760738 If "limit" is set and > 0, will only return that many elements. """
761739 self .wait_for_ready_state_complete ()
762- if page_utils .is_xpath_selector (selector ):
763- by = By .XPATH
764- if page_utils .is_link_text_selector (selector ):
765- selector = page_utils .get_link_text_from_selector (selector )
766- by = By .LINK_TEXT
740+ selector , by = self .__recalculate_selector (selector , by )
767741 v_elems = page_actions .find_visible_elements (self .driver , selector , by )
768742 if limit and limit > 0 and len (v_elems ) > limit :
769743 v_elems = v_elems [:limit ]
@@ -1965,12 +1939,10 @@ def jquery_update_text(self, selector, new_value, by=By.CSS_SELECTOR,
19651939 self .__demo_mode_pause_if_active ()
19661940
19671941 def hover_on_element (self , selector , by = By .CSS_SELECTOR ):
1942+ selector , by = self .__recalculate_selector (selector , by )
19681943 if page_utils .is_xpath_selector (selector ):
19691944 selector = self .convert_to_css_selector (selector , By .XPATH )
19701945 by = By .CSS_SELECTOR
1971- if page_utils .is_link_text_selector (selector ):
1972- selector = page_utils .get_link_text_from_selector (selector )
1973- by = By .LINK_TEXT
19741946 self .wait_for_element_visible (
19751947 selector , by = by , timeout = settings .SMALL_TIMEOUT )
19761948 self .__demo_mode_highlight_if_active (selector , by )
@@ -1983,20 +1955,12 @@ def hover_and_click(self, hover_selector, click_selector,
19831955 timeout = settings .SMALL_TIMEOUT ):
19841956 if self .timeout_multiplier and timeout == settings .SMALL_TIMEOUT :
19851957 timeout = self .__get_new_timeout (timeout )
1986- if page_utils .is_xpath_selector (hover_selector ):
1987- hover_selector = self .convert_to_css_selector (
1988- hover_selector , By .XPATH )
1989- hover_by = By .CSS_SELECTOR
1990- if page_utils .is_xpath_selector (click_selector ):
1991- click_by = By .XPATH
1992- if page_utils .is_link_text_selector (hover_selector ):
1993- hover_selector = page_utils .get_link_text_from_selector (
1994- hover_selector )
1995- hover_by = By .LINK_TEXT
1996- if page_utils .is_link_text_selector (click_selector ):
1997- click_selector = page_utils .get_link_text_from_selector (
1998- click_selector )
1999- click_by = By .LINK_TEXT
1958+ hover_selector , hover_by = self .__recalculate_selector (
1959+ hover_selector , hover_by )
1960+ hover_selector = self .convert_to_css_selector (
1961+ hover_selector , hover_by )
1962+ click_selector , click_by = self .__recalculate_selector (
1963+ click_selector , click_by )
20001964 self .wait_for_element_visible (
20011965 hover_selector , by = hover_by , timeout = timeout )
20021966 self .__demo_mode_highlight_if_active (hover_selector , hover_by )
@@ -2164,11 +2128,7 @@ def wait_for_element_present(self, selector, by=By.CSS_SELECTOR,
21642128 The element does not need be visible (it may be hidden). """
21652129 if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
21662130 timeout = self .__get_new_timeout (timeout )
2167- if page_utils .is_xpath_selector (selector ):
2168- by = By .XPATH
2169- if page_utils .is_link_text_selector (selector ):
2170- selector = page_utils .get_link_text_from_selector (selector )
2171- by = By .LINK_TEXT
2131+ selector , by = self .__recalculate_selector (selector , by )
21722132 return page_actions .wait_for_element_present (
21732133 self .driver , selector , by , timeout )
21742134
@@ -2200,11 +2160,7 @@ def wait_for_element_visible(self, selector, by=By.CSS_SELECTOR,
22002160 timeout = settings .LARGE_TIMEOUT ):
22012161 """ Waits for an element to appear in the HTML of a page.
22022162 The element must be visible (it cannot be hidden). """
2203- if page_utils .is_xpath_selector (selector ):
2204- by = By .XPATH
2205- if page_utils .is_link_text_selector (selector ):
2206- selector = page_utils .get_link_text_from_selector (selector )
2207- by = By .LINK_TEXT
2163+ selector , by = self .__recalculate_selector (selector , by )
22082164 return page_actions .wait_for_element_visible (
22092165 self .driver , selector , by , timeout )
22102166
@@ -2232,11 +2188,7 @@ def assert_element(self, selector, by=By.CSS_SELECTOR,
22322188 self .wait_for_element_visible (selector , by = by , timeout = timeout )
22332189
22342190 if self .demo_mode :
2235- if page_utils .is_xpath_selector (selector ):
2236- by = By .XPATH
2237- if page_utils .is_link_text_selector (selector ):
2238- selector = page_utils .get_link_text_from_selector (selector )
2239- by = By .LINK_TEXT
2191+ selector , by = self .__recalculate_selector (selector , by )
22402192 messenger_post = "ASSERT %s: %s" % (by , selector )
22412193 self .__highlight_with_assert_success (messenger_post , selector , by )
22422194 return True
@@ -2259,11 +2211,7 @@ def wait_for_text_visible(self, text, selector="html", by=By.CSS_SELECTOR,
22592211 timeout = settings .LARGE_TIMEOUT ):
22602212 if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
22612213 timeout = self .__get_new_timeout (timeout )
2262- if page_utils .is_xpath_selector (selector ):
2263- by = By .XPATH
2264- if page_utils .is_link_text_selector (selector ):
2265- selector = page_utils .get_link_text_from_selector (selector )
2266- by = By .LINK_TEXT
2214+ selector , by = self .__recalculate_selector (selector , by )
22672215 return page_actions .wait_for_text_visible (
22682216 self .driver , text , selector , by , timeout )
22692217
@@ -2272,11 +2220,7 @@ def wait_for_exact_text_visible(self, text, selector="html",
22722220 timeout = settings .LARGE_TIMEOUT ):
22732221 if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
22742222 timeout = self .__get_new_timeout (timeout )
2275- if page_utils .is_xpath_selector (selector ):
2276- by = By .XPATH
2277- if page_utils .is_link_text_selector (selector ):
2278- selector = page_utils .get_link_text_from_selector (selector )
2279- by = By .LINK_TEXT
2223+ selector , by = self .__recalculate_selector (selector , by )
22802224 return page_actions .wait_for_exact_text_visible (
22812225 self .driver , text , selector , by , timeout )
22822226
@@ -2313,11 +2257,7 @@ def assert_text(self, text, selector="html", by=By.CSS_SELECTOR,
23132257 self .wait_for_text_visible (text , selector , by = by , timeout = timeout )
23142258
23152259 if self .demo_mode :
2316- if page_utils .is_xpath_selector (selector ):
2317- by = By .XPATH
2318- if page_utils .is_link_text_selector (selector ):
2319- selector = page_utils .get_link_text_from_selector (selector )
2320- by = By .LINK_TEXT
2260+ selector , by = self .__recalculate_selector (selector , by )
23212261 messenger_post = ("ASSERT TEXT {%s} in %s: %s"
23222262 % (text , by , selector ))
23232263 self .__highlight_with_assert_success (messenger_post , selector , by )
@@ -2336,11 +2276,7 @@ def assert_exact_text(self, text, selector="html", by=By.CSS_SELECTOR,
23362276 text , selector , by = by , timeout = timeout )
23372277
23382278 if self .demo_mode :
2339- if page_utils .is_xpath_selector (selector ):
2340- by = By .XPATH
2341- if page_utils .is_link_text_selector (selector ):
2342- selector = page_utils .get_link_text_from_selector (selector )
2343- by = By .LINK_TEXT
2279+ selector , by = self .__recalculate_selector (selector , by )
23442280 messenger_post = ("ASSERT TEXT {%s} in %s: %s"
23452281 % (text , by , selector ))
23462282 self .__highlight_with_assert_success (messenger_post , selector , by )
@@ -2447,11 +2383,7 @@ def wait_for_element_not_visible(self, selector, by=By.CSS_SELECTOR,
24472383 to qualify as not visible. """
24482384 if self .timeout_multiplier and timeout == settings .LARGE_TIMEOUT :
24492385 timeout = self .__get_new_timeout (timeout )
2450- if page_utils .is_xpath_selector (selector ):
2451- by = By .XPATH
2452- if page_utils .is_link_text_selector (selector ):
2453- selector = page_utils .get_link_text_from_selector (selector )
2454- by = By .LINK_TEXT
2386+ selector , by = self .__recalculate_selector (selector , by )
24552387 return page_actions .wait_for_element_not_visible (
24562388 self .driver , selector , by , timeout )
24572389
@@ -3072,6 +3004,13 @@ def __recalculate_selector(self, selector, by):
30723004 if page_utils .is_link_text_selector (selector ):
30733005 selector = page_utils .get_link_text_from_selector (selector )
30743006 by = By .LINK_TEXT
3007+ if page_utils .is_partial_link_text_selector (selector ):
3008+ selector = page_utils .get_partial_link_text_from_selector (selector )
3009+ by = By .PARTIAL_LINK_TEXT
3010+ if page_utils .is_name_selector (selector ):
3011+ name = page_utils .get_name_from_selector (selector )
3012+ selector = '[name="%s"]' % name
3013+ by = By .CSS_SELECTOR
30753014 return (selector , by )
30763015
30773016 def __make_css_match_first_element_only (self , selector ):
0 commit comments