Ejemplo n.º 1
0
    def deselect(self, drop_down_label):
        '''
        This routine deselects the available option from dropdown
        Args:
            drop_down_label (str): Label of the dropdown
        Returns:
            True or False based on deselecting drop down
        '''

        try:
            index = 1
            self.button(
                set_locator(WD_PF.DROPDOWN.CLEAR_VALUE_XPATH,
                            (drop_down_label, str(index))))

            dropdown_text = self.get_text(
                set_locator(WD_PF.DROPDOWN.LABEL_XPATH,
                            (drop_down_label, str(index))))

            if drop_down_label in dropdown_text:
                return True
            return False

        except NoSuchElementException:
            return True

        except Exception:
            raise
Ejemplo n.º 2
0
    def select(self,
               drop_down_label,
               value_to_select,
               index=1,
               is_clear_existing_value=False,
               is_clear_all=False,
               timeout=180):
        '''
        This routines enable to select an option from the dropdown.
        Args:
            drop_down_label (str): Label of the dropdown
            value_to_select (any):  Value to select from the dropdown
            index (int):  index th drop down (with same label) from the page.
            is_clear_existing_value (bool): To clear existing values
            timeout (int): timeout in seconds
        '''

        try:
            label_locator = set_locator(WD_PF.DROPDOWN.LABEL_XPATH,
                                        (drop_down_label, str(index)))

            negative_case = False
            if not value_to_select:
                negative_case = True
            if is_clear_existing_value or negative_case:
                if is_clear_all:
                    clear_locator = set_locator(WD_PF.DROPDOWN.CLEAR_ALL_XPATH,
                                                (drop_down_label, str(index)))
                else:
                    clear_locator = set_locator(
                        WD_PF.DROPDOWN.CLEAR_VALUE_XPATH,
                        (drop_down_label, str(index)))
                if negative_case:
                    if drop_down_label not in self.get_text(label_locator):
                        self.button(clear_locator)
                    return
                self.button(clear_locator)

            self.wait_until_element_present(label_locator, timeout)
            self.scroll_into_view(label_locator)
            self.wait_until_element_is_clickable(label_locator, timeout)
            if self.is_element_absent(label_locator):
                self.scroll_into_view(label_locator)
            time.sleep(1)
            self.button(label_locator)

            value_locator = set_locator(WD_PF.DROPDOWN.SELECT_VALUE_XPATH,
                                        value_to_select)

            if self.is_element_absent(value_locator):
                self.scroll_into_view(value_locator)
            self.button(value_locator)

        except TimeoutException:
            LOG.error("failed to find element {}".format(label_locator[1]))
            raise NoSuchElementException

        except Exception:
            raise
Ejemplo n.º 3
0
    def select_by_value_locator(self,
                                drop_down_label,
                                value_locator,
                                index=1,
                                timeout=180):
        '''
        This routine allows selection of drop down value by the xpath
        Args:
            drop_down_label (str): Label of the dropdown
            value_locator (obj): locator of the dropdown value
            index (int):  index th drop down (with same label) from the page.
            timeout (int): timeout in seconds
        '''

        try:
            label_locator = set_locator(WD_PF.DROPDOWN.LABEL_XPATH,
                                        (drop_down_label, str(index)))

            self.wait_until_element_present(label_locator, timeout)
            self.wait_until_element_is_clickable(label_locator, timeout)
            if self.is_element_absent(label_locator):
                self.scroll_into_view(label_locator)
            time.sleep(1)
            self.button(label_locator)
            if self.is_element_absent(value_locator):
                self.scroll_into_view(value_locator)
            self.button(value_locator)

        except TimeoutException:
            LOG.error("failed to find element {}".format(label_locator[1]))
            raise NoSuchElementException

        except Exception:
            raise
Ejemplo n.º 4
0
    def get_all_options(self, drop_down_label, timeout=180):
        '''
        This routines returns all the available options from dropdown
        Args:
            drop_down_label (str): Label of the dropdown
            index (int):  index th drop down (with same label) from the page.
            timeout (int): timeout in seconds
        Returns:
            list of available options
        '''
        try:
            label_locator = set_locator(WD_PF.DROPDOWN.SELECT_ARROW_XPATH,
                                        drop_down_label)

            self.wait_until_element_present(label_locator, timeout)
            self.wait_until_element_is_clickable(label_locator, timeout)
            self.scroll_into_view(label_locator)
            time.sleep(1)
            self.button(label_locator)
            options_locator = WD_PF.DROPDOWN.SELECT_OPTIONS_XPATH
            options_text = self.driver.find_element(*options_locator).text
            options_list = options_text.split("\n")
            LOG.info("available options: %s" % options_list)
            return options_list

        except TimeoutException:
            LOG.error("failed to find element {}".format(label_locator[1]))
            raise NoSuchElementException

        except Exception:
            raise
Ejemplo n.º 5
0
    def select_by_label_xpath(self, label_xpath, value_to_select, timeout=180):
        '''
        Enables to select an option from dropdown using label_xpath
        Args:
            label_xpath (tuple) : label xpath by xpath locator
            value_to_select (str) : dropdown value
            timeout (int): timeout in seconds
        '''

        try:
            negative_case = False
            if not value_to_select:
                negative_case = True
            if negative_case:
                clear_xpath = list(label_xpath)
                clear_xpath[1] += WD_PF.DROPDOWN.CLEAR_VALUE
                clear_xpath = tuple(clear_xpath)
                clear_locator = clear_xpath
                dropdown_text = self.get_text(label_xpath)
                if "Select" not in dropdown_text and dropdown_text not in \
                        label_xpath[1]:
                    self.button(clear_locator)
                return
            self.wait_until_element_visible(label_xpath, timeout)
            self.scroll_from_top(label_xpath)
            self.wait_until_element_is_clickable(label_xpath, timeout)

            # This is the fix for the dropdown issue where we need to click on the dropdown arrow if clickable to select
            # the value.
            if isinstance(label_xpath, list):
                label_xpath = tuple(label_xpath)
            dropdown_locator = label_xpath + WD_PF.DROPDOWN.DROPDOWN_ICON
            if self.is_element_present(
                    dropdown_locator) and self.is_element_clickable(
                        dropdown_locator):
                self.button(dropdown_locator)
            else:
                self.button(label_xpath)

            value_locator = set_locator(WD_PF.DROPDOWN.SELECT_VALUE_XPATH,
                                        value_to_select)

            if self.is_element_absent(value_locator):
                self.scroll_into_view(value_locator)
            self.button(value_locator)

        except TimeoutException:
            LOG.error("failed to find element {}".format(label_xpath[1]))
            raise NoSuchElementException

        except Exception:
            raise
Ejemplo n.º 6
0
    def expand_section(self, section_name, index=1):
        '''
        This routine will expand the given section name

        Args:
            section_name (str): Section Name
            index (int): Index to the header in case of multiple header with same name

        Return:
            None
        '''

        header_locator = set_locator(WD_PF.SELENIUM.SUB_HEADER_DIV,
                                     (section_name, index))

        if self.is_element_absent(header_locator):
            header_locator = set_locator(WD_PF.SELENIUM.SUB_HEADER_SPAN,
                                         (section_name, index))

        self.scroll_from_top(header_locator)

        if "arrow-down" not in self.get_attribute("class", header_locator):
            self.toggle_entity(header_locator)
Ejemplo n.º 7
0
    def select_by_label_xpath_with_focus_on_other_element(
            self, label_xpath, value_to_select, other_element, timeout=180):
        '''
        select an option from dropdown using label_xpath and other_element
        Args:
            label_xpath (tuple) : label xpath by xpath locator
            value_to_select (str) : dropdown value
            other_element (tuple) : other element locator to be focused
            timeout (int): timeout in seconds
        '''
        try:
            self.wait_until_element_visible(label_xpath, timeout)
            self.scroll_into_view(other_element)
            self.button(label_xpath)
            self.button(
                set_locator(WD_PF.DROPDOWN.SELECT_VALUE_XPATH,
                            value_to_select))

        except TimeoutException:
            LOG.error("failed to find element {}".format(label_xpath[1]))
            raise NoSuchElementException

        except Exception:
            raise