def inventory_tabs(self, row: WebElement) -> List[WebElement]: """ Return elements of inventory tabs of a row :param row: row element (bulk edit or listing) :return: array of inventory tabs elements """ return row.find_elements(*self.INVENTORY_TABS_LOCATOR)
def set_individual_sku(self, row: WebElement, sku: str, num: int = 0, enter=True): """ Sets sku on a listing using inline edit :param row: Listing row web element :param sku: string value to set as a sku :param num: index of sku input, starting from 0 (first sku input) :param enter: confirm the sku by pressing Enter after sending keys """ try: # click on div to reveal input(s) div_elements = row.find_elements(*self._product_sku_div) click(div_elements[num]) # wait at least for first input to show up self.wait_for_child_element(row, self._product_sku_input) # find input and set the price inputs = self.product_sku_inputs(row) inputs[num].clear() if enter: sku = sku + Keys.ENTER send_keys(inputs[num], sku) except IndexError: print('Invalid sku input index: ' + str(num)) raise
def category_texts(self, row: WebElement) -> List[str]: """ Return category texts from a listing row :param row: listing row element :return: category as a list of subcategories """ cat_el = row.find_elements(*self.CATEGORY_NAMES_LOCATOR) return [e.text for e in cat_el]
def set_individual_quantity(self, row: WebElement, quantity: str, num: int = 0, enter=True): """ Sets price on a listing using inline edit :param row: Listing row web element :param quantity: string value to set as a quantity :param num: index of quantity input, starting from 0 (first quantity input) :param enter: confirm the quantity by pressing Enter after sending keys """ try: # click on div to reveal input(s) div_elements = row.find_elements(*self._product_quantity_div) click(div_elements[num]) # wait at least for first input to show up self.wait_for_child_element(row, self._product_quantity_input) # find input and set the quantity inputs = self.product_quantity_inputs(row) inputs[num].clear() if enter: quantity = quantity + Keys.ENTER send_keys(inputs[num], quantity) except IndexError: print('Invalid quantity input index: ' + str(num)) raise
def set_individual_price(self, row: WebElement, price: str, num: int = 0, enter=True): """ Sets price on a listing using inline edit :param row: Listing row web element :param price: string value to set as a price :param num: index of price input, starting from 0 (first price input) :param enter: confirm the price by pressing Enter after sending keys """ try: # click on div to reveal input(s) div_elements = row.find_elements(*self._product_price_div) self.scroll_to_element(div_elements[num], True) click(div_elements[num]) # wait at least for first input to show up self.wait_for_child_element(row, self._product_price_input) # find input and set the price inputs = self.product_price_inputs(row) inputs[num].clear() if enter: price = price + Keys.ENTER send_keys(inputs[num], price) except IndexError: print('Invalid price input index: ' + str(num)) raise
def assert_element(we: WebElement, tag_name: str, by_attr: By, attr_value: str, expected_text: str = None, is_displayed: bool = True, expected_count: int = 1, attrs: Dict = None, properties: Dict = None) -> None: """Assert that the specified element(s) are in the current webdriver page. Args: we: WebElement containing the desired content to assert. tag_name: Name of the tag of the elements to check for. by_attr: Attr to use to search for the elements. attr_value: Attr value that the by_attr must have for the elements. expected_text: Expected text contained by the elements. If None, does not check the text of the elements. is_displayed: If True, will only consider elements that are displayed to the user in the page. If False, will only consider elements that are not displayed to the user in the page. expected_count: Expected count of the matching elements in the page. attrs: Dictionary of attrs that the elements must have. properties: Dictionary of properties that the elements must have. """ tags = we.find_elements(by_attr, attr_value) tags = filter_by_displayed(tags, is_displayed) tags = filter_by_attrs(tags, attrs) tags = filter_by_properties(tags, properties) assert len(tags) == expected_count if expected_text is not None: assert_element_text(tags, expected_text, is_displayed)
def offering_options_box(self, row: WebElement, i: int = 0) -> WebElement: """ Finds and returns a box for product offering options elements :param row: row element (bulk edit or listing) :param i: first, combined (0) or second (1) property :return: box element """ return row.find_elements(*self.OFFERING_OPTIONS_BOX_LOCATOR)[i]
def bulk_individual_option_toggles(self, row: WebElement, i: int = 0) -> List[WebElement]: """ Return list of toggles in bulk edit individual Visibility :param row: bulk row :param i: property index: 0 - first property, 1 - second property :return: list of toggle elements on the left or right pane """ selector = self.BULK_EDIT_OPTION_TOGGLES_LEFT if i == 0 else self.BULK_EDIT_OPTION_TOGGLES_RIGHT return row.find_elements(*selector)
def bulk_individual_option_inputs(self, row: WebElement, i: int = 0) -> List[WebElement]: """ Return list of input boxes in bulk edit individual Price/Q/SKU :param row: bulk row :param i: property index: 0 - first property, 1 - second property :return: list of input elements on the left or right pane """ selector = self.BULK_EDIT_OPTION_INPUTS_LEFT if i == 0 else self.BULK_EDIT_OPTION_INPUTS_RIGHT return row.find_elements(*selector)
def bulk_individual_preview_options(self, row: WebElement, i: int = 0) -> List[str]: """ Return list of texts for preview name-value in bulk preview individual Price/Q/SKU (e.g. prices: ['wool', '35.50', 'cotton', '13.40']) :param row: preview row :param i: property index: 0 - first property, 1 - second property :return: list of input elements on the left or right pane """ selector = self.BULK_PREVIEW_ROW_LEFT_OPTIONS if i == 0 else self.BULK_PREVIEW_ROW_RIGHT_OPTIONS return [e.text for e in row.find_elements(*selector)]
def bulk_preview_row_header(self, row: WebElement, i: int = 0) -> List[str]: """ Return left or right header of the Bulk Variation preview row (applicable for Price, Quentity, SKU, visibility tabs) :param row: listing row (preview) :param i: property index: 0 - first property, 1 - second property :return: list of header texts (['Global Pricing', 'Price', '42']) """ selector = self.BULK_PREVIEW_ROW_LEFT_HEADER if i == 0 else self.BULK_PREVIEW_ROW_RIGHT_HEADER return [e.text for e in row.find_elements(*selector)]
def property_box(self, row: WebElement, i: int) -> WebElement: """ Finds and returns variation property box element :param row: row element (bulk edit or listing) :param i: property index: 0 - first property, 1 - second property :return: variation property box """ try: element = row.find_elements(*self.PROPERTY_BOXES_LOCATOR)[i] except IndexError: raise Exception('Property box element was not found') return element
def bulk_individual_preview_toggles(self, row: WebElement, i: int = 0) -> List[bool]: """ Return list of bools for preview of visibility - select the toggle elements and check the if the class contains 'is-true' -> selected :param row: preview row :param i: property index: 0 - first property, 1 - second property :return: list of input elements on the left or right pane """ selector = self.BULK_PREVIEW_ROW_LEFT_TOGGLES if i == 0 else self.BULK_PREVIEW_ROW_RIGHT_TOGGLES return [ 'is-true' in e.get_attribute('class').split(' ') for e in row.find_elements(*selector) ]
def _find_children_visible_enabled(elem: WebElement, tag: Tag) -> list[Optional[WebElement]]: return [e for e in elem.find_elements(By.XPATH, f".//{tag.value}") if e.is_enabled() and e.is_displayed()]
def get_lessons(module: WebElement) -> list[WebElement]: return module.find_elements(By.XPATH, './/*[@class="course__lesson-item"]')
def find_nested_elements(self, parent: WebElement, locator: Tuple[str, str]) -> List[WebElement]: return parent.find_elements(*locator)