Ejemplo n.º 1
0
def get_dd_elements_from_all_documents(locator, anchor, index, **kwargs):
    if int(index) > 0:
        index = int(index) - 1
    css_selector = CONFIG["CssSelectors"]
    if not css_selector or locator.startswith('xpath=') or locator.startswith(
            '//'):
        select = get_dropdown_element_by_locator(locator, anchor)
    elif Table.is_table_coordinates(locator):
        table = Table.ACTIVE_TABLE.update_table()
        if table is None:
            raise QWebInstanceDoesNotExistError(
                'Table has not been defined with UseTable keyword')
        locator = table.get_table_cell(locator, anchor)
        select = element.get_element_from_childnodes(
            locator, 'select', dom_traversing=False)[index]
    else:
        select = get_dropdown_element_by_css_selector(locator, anchor, index,
                                                      **kwargs)
    if not select:
        select = get_dropdown_element_by_locator(locator, anchor)
    if select:
        if CONFIG['SearchMode']:
            element.draw_borders(select)
        return Select(select)
    raise QWebElementNotFoundError('No matching elements found')
Ejemplo n.º 2
0
def use_table(
        locator,
        anchor="1",
        timeout=0,
        parent=None,  # pylint: disable=unused-argument
        child=None,
        level=1,
        index=1):
    r"""Define table for all other table keywords.

    Sets active table for other keywords.

    Examples
    --------
    .. code-block:: robotframework

         UseTable       Calendar    Qentinel
         UseTable       Calendar    parent=True # Use parent table of Calendar
         UseTable       Calendar    child=True  # Use child table of Calendar


    Parameters
    ----------
    locator : str
        Text that locates the table. The table that is closest
        to the text is selected. Also one can use xpath by adding xpath= prefix
        and then the xpath. Error is raised if the xpath matches to multiple
        elements. When using XPaths, the equal sign "=" must be escaped with a "\".
    anchor : str
        Index number or text near the input field's locator element.
        If the page contains many places where the locator is then anchor is used
        to select the wanted item. Index number selects the item from the list
        of matching entries starting with 1. Text selects the entry with the closest
        distance.
    timeout : str | int
        How long we search before failing. Default = Search Strategy default timeout (10s)
    parent : bool
        Use when correct table is parent of located table
    child : bool
        Use when correct table is child of located table
    level : int
        If wanted parent table is not the first one use level to pick correct one.
        For example level=2 means parent table of parent table etc.
    index : int
        If multiple childtables exists. Use index to pick correct one.
    """
    global ACTIVE_TABLE  # pylint:disable=global-statement
    ACTIVE_TABLE = Table.from_table_instance(locator, anchor, parent, child,
                                             level, index)
Ejemplo n.º 3
0
def get_checkbox_elements_from_all_documents(locator, anchor, index, **kwargs):
    """Function for finding checkbox elements.
    Parameters
    ----------
    locator : str
        Label text or attribute that points to the checkbox.
    anchor : str
        in case there is duplicates.
    index : int
        If multiple matches. Use index to pick correct one.
    Returns
    -------
    WebElement
    """
    index = int(index) - 1
    css_selector = CONFIG["CssSelectors"]
    css = '[type="checkbox"], [role="checkbox"]'
    if Table.is_table_coordinates(locator):
        table = Table.ACTIVE_TABLE.update_table()
        if table is None:
            raise QWebInstanceDoesNotExistError(
                'Table has not been defined with UseTable keyword')
        locator_element = table.get_table_cell(locator, anchor)
        checkbox_element = element.get_element_from_childnodes(
            locator_element, css, dom_traversing=False, **kwargs)
        if checkbox_element:
            return checkbox_element[index], locator_element
        raise QWebElementNotFoundError('No matching checkbox found')
    if not css_selector or locator.startswith('xpath=') or locator.startswith(
            '//'):
        checkbox_element, locator_element = get_checkbox_by_locator(
            locator, anchor=anchor)
    else:
        checkbox_element, locator_element = get_checkbox_by_css_selector(
            locator, anchor=anchor, index=index, **kwargs)
        if not checkbox_element:
            checkbox_element, locator_element = get_checkbox_by_locator(
                locator, anchor)
    if checkbox_element:
        return checkbox_element, locator_element
    raise QWebElementNotFoundError('No matching element found')
Ejemplo n.º 4
0
def get_input_elements_from_all_documents(locator,
                                          anchor,
                                          timeout,
                                          index=1,
                                          enable_check=False,
                                          **kwargs):  # pylint: disable=unused-argument
    """Function for finding input elements.
    Parameters
    ----------
    locator : str
       Label text or attribute that points to the checkbox.
    anchor : str
       in case there is duplicates.
    timeout : str
       How long we are finding before fail.
       Default = Search Strategy global default = 10 sec)
    index : int
       If table cell contains more than one input elements or if there is some kind of
       nested structure inside of given input index may needed. Default = 1 (first)
    enable_check : bool
        When CSS Selectors are used, we are not return disabled input element
        always by default. Element is needed with verify input status kw
        so if enable_check= True, disabled input_element is returned
    kwargs:
        limit_traverse : bool
            If set to false. We are heading up to fifth parent element if needed when
            finding relative input element for some label text.
    Returns
    -------
    WebElement
    """
    index = int(index) - 1
    css = 'input:not([type="hidden"]):not([type="submit"]):not([type="button"])' \
          ':not([type="reset"]):not([type="checkbox"]):not([type="radio"])' \
          ':not([aria-hidden="true"]),' \
          'textarea:not([type="hidden"]),[contenteditable="true"]'
    kwargs['css'] = kwargs.get('css', css)
    if Table.is_table_coordinates(locator):
        table = Table.ACTIVE_TABLE.update_table()
        if table is None:
            raise QWebInstanceDoesNotExistError(
                'Table has not been defined with UseTable keyword')
        locator_element = table.get_table_cell(locator, anchor)
        input_element = element.get_element_from_childnodes(
            locator_element, kwargs['css'], dom_traversing=False)
        if input_element:
            return input_element[index]
        raise QWebElementNotFoundError('No matching table input found')
    css_selector = CONFIG["CssSelectors"]
    if not css_selector or locator.startswith('xpath=') or locator.startswith(
            '//'):
        input_element = get_input_element_by_locator(locator, anchor, **kwargs)
    else:
        logger.debug('Uses CSS-selectors to locate element')
        input_element = get_input_element_by_css_selector(
            locator, anchor, index, enable_check, **kwargs)
        if not input_element:
            input_element = get_input_element_by_locator(
                locator, anchor, **kwargs)
    if input_element:
        if CONFIG['SearchMode']:
            element.draw_borders(input_element)
        return input_element
    raise QWebElementNotFoundError('No matching input elements found')