3131from  selenium .common .exceptions  import  StaleElementReferenceException 
3232from  selenium .common .exceptions  import  WebDriverException 
3333from  selenium .webdriver .common .alert  import  Alert 
34+ from  selenium .webdriver .common .by  import  ByType 
3435from  selenium .webdriver .remote .webdriver  import  WebDriver 
3536from  selenium .webdriver .remote .webdriver  import  WebElement 
37+ from  selenium .webdriver .support .relative_locator  import  RelativeBy 
3638
3739""" 
3840 * Canned "Expected Conditions" which are generally useful within webdriver 
4345T  =  TypeVar ("T" )
4446
4547WebDriverOrWebElement  =  Union [WebDriver , WebElement ]
48+ LocatorType  =  Union [Tuple [ByType , str ], Tuple [RelativeBy , None ]]
4649
4750
4851def  title_is (title : str ) ->  Callable [[WebDriver ], bool ]:
@@ -72,7 +75,7 @@ def _predicate(driver: WebDriver):
7275    return  _predicate 
7376
7477
75- def  presence_of_element_located (locator : Tuple [ str ,  str ] ) ->  Callable [[WebDriverOrWebElement ], WebElement ]:
78+ def  presence_of_element_located (locator : LocatorType ) ->  Callable [[WebDriverOrWebElement ], WebElement ]:
7679    """An expectation for checking that an element is present on the DOM of a 
7780    page. This does not necessarily mean that the element is visible. 
7881
@@ -141,7 +144,7 @@ def _predicate(driver: WebDriver):
141144
142145
143146def  visibility_of_element_located (
144-     locator : Tuple [ str ,  str ] 
147+     locator : LocatorType 
145148) ->  Callable [[WebDriverOrWebElement ], Union [Literal [False ], WebElement ]]:
146149    """An expectation for checking that an element is present on the DOM of a 
147150    page and visible. Visibility means that the element is not only displayed 
@@ -179,7 +182,7 @@ def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[L
179182    return  element  if  element .is_displayed () ==  visibility  else  False 
180183
181184
182- def  presence_of_all_elements_located (locator : Tuple [ str ,  str ] ) ->  Callable [[WebDriverOrWebElement ], List [WebElement ]]:
185+ def  presence_of_all_elements_located (locator : LocatorType ) ->  Callable [[WebDriverOrWebElement ], List [WebElement ]]:
183186    """An expectation for checking that there is at least one element present 
184187    on a web page. 
185188
@@ -193,7 +196,7 @@ def _predicate(driver: WebDriverOrWebElement):
193196    return  _predicate 
194197
195198
196- def  visibility_of_any_elements_located (locator : Tuple [ str ,  str ] ) ->  Callable [[WebDriverOrWebElement ], List [WebElement ]]:
199+ def  visibility_of_any_elements_located (locator : LocatorType ) ->  Callable [[WebDriverOrWebElement ], List [WebElement ]]:
197200    """An expectation for checking that there is at least one element visible 
198201    on a web page. 
199202
@@ -208,7 +211,7 @@ def _predicate(driver: WebDriverOrWebElement):
208211
209212
210213def  visibility_of_all_elements_located (
211-     locator : Tuple [ str ,  str ] 
214+     locator : LocatorType 
212215) ->  Callable [[WebDriverOrWebElement ], Union [List [WebElement ], Literal [False ]]]:
213216    """An expectation for checking that all elements are present on the DOM of 
214217    a page and visible. Visibility means that the elements are not only 
@@ -231,7 +234,7 @@ def _predicate(driver: WebDriverOrWebElement):
231234    return  _predicate 
232235
233236
234- def  text_to_be_present_in_element (locator : Tuple [ str ,  str ] , text_ : str ) ->  Callable [[WebDriverOrWebElement ], bool ]:
237+ def  text_to_be_present_in_element (locator : LocatorType , text_ : str ) ->  Callable [[WebDriverOrWebElement ], bool ]:
235238    """An expectation for checking if the given text is present in the 
236239    specified element. 
237240
@@ -249,7 +252,7 @@ def _predicate(driver: WebDriverOrWebElement):
249252
250253
251254def  text_to_be_present_in_element_value (
252-     locator : Tuple [ str ,  str ] , text_ : str 
255+     locator : LocatorType , text_ : str 
253256) ->  Callable [[WebDriverOrWebElement ], bool ]:
254257    """An expectation for checking if the given text is present in the 
255258    element's value. 
@@ -268,7 +271,7 @@ def _predicate(driver: WebDriverOrWebElement):
268271
269272
270273def  text_to_be_present_in_element_attribute (
271-     locator : Tuple [ str ,  str ] , attribute_ : str , text_ : str 
274+     locator : LocatorType , attribute_ : str , text_ : str 
272275) ->  Callable [[WebDriverOrWebElement ], bool ]:
273276    """An expectation for checking if the given text is present in the 
274277    element's attribute. 
@@ -288,7 +291,7 @@ def _predicate(driver: WebDriverOrWebElement):
288291    return  _predicate 
289292
290293
291- def  frame_to_be_available_and_switch_to_it (locator : Union [Tuple [ str ,  str ] , str ]) ->  Callable [[WebDriver ], bool ]:
294+ def  frame_to_be_available_and_switch_to_it (locator : Union [LocatorType , str ]) ->  Callable [[WebDriver ], bool ]:
292295    """An expectation for checking whether the given frame is available to 
293296    switch to. 
294297
@@ -310,7 +313,7 @@ def _predicate(driver: WebDriver):
310313
311314
312315def  invisibility_of_element_located (
313-     locator : Union [WebElement , Tuple [ str ,  str ] ]
316+     locator : Union [WebElement , LocatorType ]
314317) ->  Callable [[WebDriverOrWebElement ], Union [WebElement , bool ]]:
315318    """An Expectation for checking that an element is either invisible or not 
316319    present on the DOM. 
@@ -336,7 +339,7 @@ def _predicate(driver: WebDriverOrWebElement):
336339
337340
338341def  invisibility_of_element (
339-     element : Union [WebElement , Tuple [ str ,  str ] ]
342+     element : Union [WebElement , LocatorType ]
340343) ->  Callable [[WebDriverOrWebElement ], Union [WebElement , bool ]]:
341344    """An Expectation for checking that an element is either invisible or not 
342345    present on the DOM. 
@@ -347,7 +350,7 @@ def invisibility_of_element(
347350
348351
349352def  element_to_be_clickable (
350-     mark : Union [WebElement , Tuple [ str ,  str ] ]
353+     mark : Union [WebElement , LocatorType ]
351354) ->  Callable [[WebDriverOrWebElement ], Union [Literal [False ], WebElement ]]:
352355    """An Expectation for checking an element is visible and enabled such that 
353356    you can click it. 
@@ -399,7 +402,7 @@ def _predicate(_):
399402    return  _predicate 
400403
401404
402- def  element_located_to_be_selected (locator : Tuple [ str ,  str ] ) ->  Callable [[WebDriverOrWebElement ], bool ]:
405+ def  element_located_to_be_selected (locator : LocatorType ) ->  Callable [[WebDriverOrWebElement ], bool ]:
403406    """An expectation for the element to be located is selected. 
404407
405408    locator is a tuple of (by, path) 
@@ -424,7 +427,7 @@ def _predicate(_):
424427
425428
426429def  element_located_selection_state_to_be (
427-     locator : Tuple [ str ,  str ] , is_selected : bool 
430+     locator : LocatorType , is_selected : bool 
428431) ->  Callable [[WebDriverOrWebElement ], bool ]:
429432    """An expectation to locate an element and check if the selection state 
430433    specified is in that state. 
@@ -474,7 +477,7 @@ def _predicate(driver: WebDriver):
474477    return  _predicate 
475478
476479
477- def  element_attribute_to_include (locator : Tuple [ str ,  str ] , attribute_ : str ) ->  Callable [[WebDriverOrWebElement ], bool ]:
480+ def  element_attribute_to_include (locator : LocatorType , attribute_ : str ) ->  Callable [[WebDriverOrWebElement ], bool ]:
478481    """An expectation for checking if the given attribute is included in the 
479482    specified element. 
480483
0 commit comments