def __check_elements_count( self, locator: Tuple[By, str], state: Callable[[WebElement], bool] = Displayed(), expected_count: ElementsCount = ElementsCount.ANY, ) -> None: if expected_count == ElementsCount.ZERO: self._conditional_wait.wait_for_true( lambda: not any( self._element_finder.find_elements(locator, state, timedelta())), message=self._localization_manager.get_localized_message( "loc.elements.found.but.should.not", locator, "desired"), ) elif expected_count == ElementsCount.MORE_THAN_ZERO: self._conditional_wait.wait_for_true( lambda: any( self._element_finder.find_elements(locator, state, timedelta())), message=self._localization_manager.get_localized_message( "loc.no.elements.found.by.locator", locator), ) elif expected_count == ElementsCount.ANY: self._conditional_wait.wait_for( lambda: self._element_finder.find_elements( locator, state, timedelta()) is not None) else: raise ValueError(f"No such expected value: {expected_count}")
def find_elements( self, element_supplier: Callable[ [Tuple[By, str], str, Callable[[WebElement], bool]], TElement], locator: Tuple[By, str], name: str = "", state: Callable[[WebElement], bool] = Displayed(), expected_count: ElementsCount = ElementsCount.ANY, ) -> List[TElement]: """ Find list of elements by base locator. :param element_supplier: Callable object that defines constructor of element in case of custom element. :param locator: Base elements locator. :param name: Elements name. :param state: Elements state. :param expected_count: Expected number of elements that have to be found (zero, more than zero, any). :return: List of elements that found by locator. """ self.__check_elements_count(locator, state, expected_count) web_elements = self._element_finder.find_elements( locator, state, timedelta()) found_elements: List[TElement] = [] for element_index in range(1, len(web_elements) + 1): element_locator = self._generate_xpath_locator( locator, element_index) element_name = f"{name if name else 'element'} {element_index}" found_elements.append( element_supplier(element_locator, element_name, state)) return found_elements
def find_child_elements( self, parent_element: AbstractElement, element_supplier: Callable[ [Tuple[By, str], str, Callable[[WebElement], bool]], TElement], child_locator: Tuple[By, str], name: str = "", state: Callable[[WebElement], bool] = Displayed(), expected_count: ElementsCount = ElementsCount.ANY, ) -> List[TElement]: """ Find child element by its locator relative to parent element. :param parent_element: Parent element. :param element_supplier: Callable object that defines constructor of element in case of custom element. :param child_locator: Locator of child element relative to its parent. :param name: Child element name. :param state: Child element state. :param expected_count: Expected number of elements that have to be found (zero, more than zero, any). :return: Instance of child element. """ elements_name = name if name else f"Child element of {parent_element.name}" locator = self._generate_absolute_child_locator( parent_element.locator, child_locator) return self.find_elements(element_supplier, locator, elements_name, state, expected_count)
def wait_for_displayed( self, timeout: timedelta = cast(timedelta, None)) -> bool: """ Wait for element is displayed on the page. :param timeout: Timeout for waiting. Default value is taken from TimeoutConfiguration. :return: true if element displayed after waiting, false otherwise. """ return self.__is_any_element_found(timeout, Displayed())
def find_child_element( self, supplier: Callable[[Tuple[By, str], str, Callable], TElement], child_locator: Tuple[By, str], name: str, state: Callable[[WebElement], bool] = Displayed(), ) -> TElement: """ Find child element of type TElement of current element by its locator. :param supplier: Callable object that defines constructor of child element in case of custom element. :param child_locator: Locator of child element. :param name: Child element name. :param state: Child element state. :return: Instance of child element. """ pass
def get_custom_element( self, element_supplier: Callable[ [Tuple[By, str], str, Callable[[WebElement], bool]], TElement], locator: Tuple[By, str], name: str, state: Callable[[WebElement], bool] = Displayed(), ) -> TElement: """ Create custom element according to passed parameters. :param element_supplier: Callable object that defines constructor of element. :param locator: Locator of the target element. :param name: Name of the target element. :param state: State of the target element. :return: Instance of custom element. """ pass
def find_child_elements( self, supplier: Callable[[Tuple[By, str], str, Callable], TElement], child_locator: Tuple[By, str], name: str, state: Callable[[WebElement], bool] = Displayed(), expected_count: ElementsCount = ElementsCount.ANY, ) -> List[TElement]: """ Find child elements of type TElement of current element by its locator. :param supplier: Callable object that defines constructor of child element in case of custom element. :param child_locator: Locator of child elements relative to their parent. :param name: Child elements name. :param state: Child elements state. :param expected_count: Expected number of elements that have to be found (zero, more than zero, any). :return: List of child elements. """ pass
def find_elements( self, element_supplier: Callable[ [Tuple[By, str], str, Callable[[WebElement], bool]], TElement], locator: Tuple[By, str], name: str = "", state: Callable[[WebElement], bool] = Displayed(), expected_count: ElementsCount = ElementsCount.ANY, ) -> List[TElement]: """ Find list of elements by base locator. :param element_supplier: Callable object that defines constructor of element in case of custom element. :param locator: Base elements locator. :param name: Elements name. :param state: Elements state. :param expected_count: Expected number of elements that have to be found (zero, more than zero, any). :return: List of elements that found by locator. """ pass
def find_child_element( self, parent_element: AbstractElement, element_supplier: Callable[ [Tuple[By, str], str, Callable[[WebElement], bool]], TElement], child_locator: Tuple[By, str], name: str = "", state: Callable[[WebElement], bool] = Displayed(), ) -> TElement: """ Find child element by its locator relative to parent element. :param parent_element: Parent element. :param element_supplier: Callable object that defines constructor of element in case of custom element. :param child_locator: Locator of child element relative to its parent. :param name: Child element name. :param state: Child element state. :return: Instance of child element. """ pass
def find_child_element( self, parent_element: AbstractElement, element_supplier: Callable[ [Tuple[By, str], str, Callable[[WebElement], bool]], TElement], child_locator: Tuple[By, str], name: str = "", state: Callable[[WebElement], bool] = Displayed(), ) -> TElement: """ Find child element by its locator relative to parent element. :param parent_element: Parent element. :param element_supplier: Callable object that defines constructor of element in case of custom element. :param child_locator: Locator of child element relative to its parent. :param name: Child element name. :param state: Child element state. :return: Instance of child element. """ element_name = name if name else f"Child element of {parent_element.name}" locator = self._generate_absolute_child_locator( parent_element.locator, child_locator) return element_supplier(locator, element_name, state)