2727 WebDriverException ,
2828)
2929from selenium .webdriver .common .alert import Alert
30+ from selenium .webdriver .common .by import ByType
3031from selenium .webdriver .remote .webdriver import WebDriver , WebElement
32+ from selenium .webdriver .support .relative_locator import RelativeBy
3133
3234"""
3335 * Canned "Expected Conditions" which are generally useful within webdriver
3840T = TypeVar ("T" )
3941
4042WebDriverOrWebElement = Union [WebDriver , WebElement ]
43+ LocatorType = Union [Tuple [ByType , str ], Tuple [RelativeBy , None ]]
4144
4245
4346def title_is (title : str ) -> Callable [[WebDriver ], bool ]:
@@ -79,7 +82,7 @@ def _predicate(driver: WebDriver):
7982 return _predicate
8083
8184
82- def presence_of_element_located (locator : Tuple [ str , str ] ) -> Callable [[WebDriverOrWebElement ], WebElement ]:
85+ def presence_of_element_located (locator : LocatorType ) -> Callable [[WebDriverOrWebElement ], WebElement ]:
8386 """An expectation for checking that an element is present on the DOM of a
8487 page. This does not necessarily mean that the element is visible.
8588
@@ -189,7 +192,7 @@ def _predicate(driver: WebDriver):
189192
190193
191194def visibility_of_element_located (
192- locator : Tuple [ str , str ] ,
195+ locator : LocatorType ,
193196) -> Callable [[WebDriverOrWebElement ], Union [Literal [False ], WebElement ]]:
194197 """An expectation for checking that an element is present on the DOM of a
195198 page and visible. Visibility means that the element is not only displayed
@@ -272,7 +275,7 @@ def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[L
272275 return element if element .is_displayed () == visibility else False
273276
274277
275- def presence_of_all_elements_located (locator : Tuple [ str , str ] ) -> Callable [[WebDriverOrWebElement ], List [WebElement ]]:
278+ def presence_of_all_elements_located (locator : LocatorType ) -> Callable [[WebDriverOrWebElement ], List [WebElement ]]:
276279 """An expectation for checking that there is at least one element present
277280 on a web page.
278281
@@ -299,7 +302,7 @@ def _predicate(driver: WebDriverOrWebElement):
299302 return _predicate
300303
301304
302- def visibility_of_any_elements_located (locator : Tuple [ str , str ] ) -> Callable [[WebDriverOrWebElement ], List [WebElement ]]:
305+ def visibility_of_any_elements_located (locator : LocatorType ) -> Callable [[WebDriverOrWebElement ], List [WebElement ]]:
303306 """An expectation for checking that there is at least one element visible
304307 on a web page.
305308
@@ -327,7 +330,7 @@ def _predicate(driver: WebDriverOrWebElement):
327330
328331
329332def visibility_of_all_elements_located (
330- locator : Tuple [ str , str ] ,
333+ locator : LocatorType ,
331334) -> Callable [[WebDriverOrWebElement ], Union [List [WebElement ], Literal [False ]]]:
332335 """An expectation for checking that all elements are present on the DOM of
333336 a page and visible. Visibility means that the elements are not only
@@ -363,7 +366,7 @@ def _predicate(driver: WebDriverOrWebElement):
363366 return _predicate
364367
365368
366- def text_to_be_present_in_element (locator : Tuple [ str , str ] , text_ : str ) -> Callable [[WebDriverOrWebElement ], bool ]:
369+ def text_to_be_present_in_element (locator : LocatorType , text_ : str ) -> Callable [[WebDriverOrWebElement ], bool ]:
367370 """An expectation for checking if the given text is present in the
368371 specified element.
369372
@@ -399,7 +402,7 @@ def _predicate(driver: WebDriverOrWebElement):
399402
400403
401404def text_to_be_present_in_element_value (
402- locator : Tuple [ str , str ] , text_ : str
405+ locator : LocatorType , text_ : str
403406) -> Callable [[WebDriverOrWebElement ], bool ]:
404407 """An expectation for checking if the given text is present in the
405408 element's value.
@@ -436,7 +439,7 @@ def _predicate(driver: WebDriverOrWebElement):
436439
437440
438441def text_to_be_present_in_element_attribute (
439- locator : Tuple [ str , str ] , attribute_ : str , text_ : str
442+ locator : LocatorType , attribute_ : str , text_ : str
440443) -> Callable [[WebDriverOrWebElement ], bool ]:
441444 """An expectation for checking if the given text is present in the
442445 element's attribute.
@@ -477,7 +480,7 @@ def _predicate(driver: WebDriverOrWebElement):
477480
478481
479482def frame_to_be_available_and_switch_to_it (
480- locator : Union [Tuple [ str , str ] , str , WebElement ],
483+ locator : Union [LocatorType , str , WebElement ],
481484) -> Callable [[WebDriver ], bool ]:
482485 """An expectation for checking whether the given frame is available to
483486 switch to.
@@ -517,7 +520,7 @@ def _predicate(driver: WebDriver):
517520
518521
519522def invisibility_of_element_located (
520- locator : Union [WebElement , Tuple [ str , str ] ],
523+ locator : Union [WebElement , LocatorType ],
521524) -> Callable [[WebDriverOrWebElement ], Union [WebElement , bool ]]:
522525 """An Expectation for checking that an element is either invisible or not
523526 present on the DOM.
@@ -565,7 +568,7 @@ def _predicate(driver: WebDriverOrWebElement):
565568
566569
567570def invisibility_of_element (
568- element : Union [WebElement , Tuple [ str , str ] ],
571+ element : Union [WebElement , LocatorType ],
569572) -> Callable [[WebDriverOrWebElement ], Union [WebElement , bool ]]:
570573 """An Expectation for checking that an element is either invisible or not
571574 present on the DOM.
@@ -592,7 +595,7 @@ def invisibility_of_element(
592595
593596
594597def element_to_be_clickable (
595- mark : Union [WebElement , Tuple [ str , str ] ],
598+ mark : Union [WebElement , LocatorType ],
596599) -> Callable [[WebDriverOrWebElement ], Union [Literal [False ], WebElement ]]:
597600 """An Expectation for checking an element is visible and enabled such that
598601 you can click it.
@@ -687,7 +690,7 @@ def _predicate(_):
687690 return _predicate
688691
689692
690- def element_located_to_be_selected (locator : Tuple [ str , str ] ) -> Callable [[WebDriverOrWebElement ], bool ]:
693+ def element_located_to_be_selected (locator : LocatorType ) -> Callable [[WebDriverOrWebElement ], bool ]:
691694 """An expectation for the element to be located is selected.
692695
693696 Parameters:
@@ -743,7 +746,7 @@ def _predicate(_):
743746
744747
745748def element_located_selection_state_to_be (
746- locator : Tuple [ str , str ] , is_selected : bool
749+ locator : LocatorType , is_selected : bool
747750) -> Callable [[WebDriverOrWebElement ], bool ]:
748751 """An expectation to locate an element and check if the selection state
749752 specified is in that state.
@@ -858,7 +861,7 @@ def _predicate(driver: WebDriver):
858861 return _predicate
859862
860863
861- def element_attribute_to_include (locator : Tuple [ str , str ] , attribute_ : str ) -> Callable [[WebDriverOrWebElement ], bool ]:
864+ def element_attribute_to_include (locator : LocatorType , attribute_ : str ) -> Callable [[WebDriverOrWebElement ], bool ]:
862865 """An expectation for checking if the given attribute is included in the
863866 specified element.
864867
0 commit comments