Esempio n. 1
0
def get_drop_down_values(locator, anchor='1', timeout=0, index=1, **kwargs):
    r"""Return all options from a dropdown menu/list.

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

        ${all_options}=     GetDropDownValues     Canis     Collie
        log     ${all_options}

    In the above example the GetDropDownValues keyword saves all items from the
    dropdown menu Canis to a variable.

    This keyword can also be used with table cells and XPaths. When using XPaths, the equal sign "="
    must be escaped with a "\".

    Parameters
    ----------
    locator : str
        Locator for searching the dropdown element. Usually some label-text
    anchor : str
        Optional parameter for locating the element if locator text is not unique
    timeout: str
        How long we try to find element before failing. Default 10 (seconds)
    index : int
        If cell contains more than one dropdown elements index is needed. Default = 1 (first)
    kwargs :
        |  Accepted kwargs:
        |       limit_traverse : False. If limit traverse is set to false we are heading up to
        |       fifth parent element if needed when finding relative input element for some label.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match
    """
    select = get_dd_elements_from_all_documents(locator, anchor, index=index, **kwargs)
    return actions.get_select_options(select, timeout=timeout)
Esempio n. 2
0
def verify_selected_option(locator, expected_option, anchor='1', timeout=0, index=1, **kwargs):
    """Verify selected option from dropdown menu/list.

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

        VerifySelectedOption    Canis   Collie

    In the above example the VerifySelectedOption keyword verifies from a dropdown
    that Collie is selected.

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

        VerifySelectedOption    r1c1          Qentinel
        VerifySelectedOption    r-1c3         Robot     #last row, third cell
        VerifySelectedOption    r?Robot/c-1   Qentinel  #row that contains text Robot, last cell

    Parameters
    ----------
    locator : str
        Locator for searching the dropdown element. Usually some label-text
    expected_option : str
        option which should be selected
    anchor : str
        Optional parameter for locating the element if locator text is not unique
    timeout: str
         How long we try to find element before failing. Default 10 (seconds)
    index : int
        If cell contains more than one dropdown elements index is needed. Default = 1 (first)
    kwargs :
        |  Accepted kwargs:
        |       limit_traverse : False. If limit traverse is set to false we are heading up to
        |       fifth parent element if needed when finding relative input element for some label.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match
    """
    select = get_dd_elements_from_all_documents(
        locator, anchor=anchor, index=index, **kwargs)
    if actions.get_selected_value(select, expected_option, timeout=timeout):
        return
Esempio n. 3
0
def get_selected(locator, anchor='1', timeout=0, index=1, **kwargs):
    """Get selected option to variable from dropdown menu/list.

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

        ${VALUE}    GetSelected    Canis

    In the above example we get selected value from dropdown Canis.

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

        ${VALUE}    GetSelected    r1c1
        ${VALUE}    GetSelected    r-1c3             #last row, third cell
        ${VALUE}    GetSelected    r?Robot/c-1      #row that contains text Robot, last cell

    Parameters
    ----------
    locator : unicode
        Locator for searching the dropdown element. Usually some label-text
    anchor : unicode
        Optional parameter for locating the element if locator text is not unique
    timeout: unicode
         How long we try to find element before failing. Default 10 (seconds)
    index : int
        If cell contains more than one dropdown elements index is needed. Default = 1 (first)
    kwargs :
        |  Accepted kwargs:
        |       limit_traverse : False. If limit traverse is set to false we are heading up to
        |       fifth parent element if needed when finding relative input element for some label.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match
    """
    select = get_dd_elements_from_all_documents(
        locator, anchor=anchor, index=index, **kwargs)
    return actions.get_selected_value(select, timeout=timeout)
Esempio n. 4
0
def verify_no_option(locator, option, anchor='1', timeout=0, index=1, **kwargs):
    r"""Verify that a given option is not in a dropdown menu/list.

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

        VerifyNoOption     Foobar    Cat

    In the above example VerifyNoOption keyword checks that the option "Cat" is not found
    from the Foobar dropdown menu/list.

    This keyword can also be used with table cells and XPaths. When using XPaths, the equal sign "="
    must be escaped with a "\".

    Parameters
    ----------
    locator : str
        Locator for searching the dropdown element. Usually some label-text
    option : str
        Option text that should not exists in options list
    anchor : str
        Optional parameter for locating the element if locator text is not unique
    timeout: str
        How long we try to find element before failing. Default 10 (seconds)
    index : int
        If cell contains more than one dropdown elements index is needed. Default = 1 (first)
    kwargs :
        |  Accepted kwargs:
        |       limit_traverse : False. If limit traverse is set to false we are heading up to
        |       fifth parent element if needed when finding relative input element for some label.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match
    """
    select = get_dd_elements_from_all_documents(locator, anchor, index=index, **kwargs)
    if actions.is_not_in_dropdown(select, option, timeout=timeout):
        return
Esempio n. 5
0
def drop_down(locator, option, anchor='1', timeout=0, index=1, **kwargs):
    """Select an option from dropdown menu/list.

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

        DropDown        Canis   Collie

    In the above example the DropDown keyword will select from a dropdown
    the option: Collie.

    How the dropdown element is searched:
    The dropdown element is first attempted to be matched based on its
    label text and then options.
    If you give one of the dropdown's options as locator, the element
    will be matched in this search pass.

    If there are multiple instances of a dropdown with text Canis on the page, first one
    will be clicked unless 'anchor' is given. You can
    specific which one should be clicked by either:

    - a number or
    - a word that is near to the word Canis

    For example

    .. code-block:: robotframework

        DropDown    Canis    Collie   anchor=3     # Uses third Canis dropdown
        DropDown    Canis    Collie   anchor=dog   # Uses Canis dropdown near the word text dog

    With table(Pick table with use table keyword first):

    .. code-block:: robotframework

        Dropdown    r1c1          Qentinel
        Dropdown    r-1c3         Robot     #last row, third cell
        Dropdown    r?Robot/c-1   Qentinel  #row that contains text Robot, last cell

    Choose dropdown option with index:

    .. code-block:: robotframework

        Dropdown    Canis       [[2]]

    Parameters
    ----------
    locator : str
        Locator for searching the dropdown element
    option : str
        Label of the option you want to select
    anchor : str
        Optional parameter for locating the element if locator text is not unique
    timeout : str | int
        How long we search before failing. Default = Search Strategy default timeout (10s)
    index : int
        If cell contains more than one dropdown elements index is needed. Default = 1 (first)
    kwargs :
        |  Accepted kwargs:
        |       limit_traverse : False. If limit traverse is set to false we are heading up to
        |       fifth parent element if needed when finding relative input element for some label.
        |       partial_match: True. If element is found by it's attribute set partial_match
        |       to True to allow partial match

    Raises
    ------
    QWebElementNotFoundErr
        Dropdown element not found
    """
    select = get_dd_elements_from_all_documents(locator, anchor, index=index, **kwargs)
    if actions.select_option(select, option, timeout=timeout):
        return
Esempio n. 6
0
def get_webelement(locator,
                   anchor='1',
                   element_type=None,
                   timeout=0,
                   **kwargs):
    r"""Get Webelement using any Paceword -stylish locator.

    Examples
    --------
    Using attributes or xpaths like with ClickElement etc. kw:s without specified
    element_type. If element_type is not specified end result is a type of list:

    .. code-block:: robotframework

        ${list of elems}    GetWebelement          click_me      tag=button
        ${list of elems}    GetWebelement          //*[@id\="click_me"]
        ${list of elems}    GetWebelement          xpath\=//*[@id\="click_me"]

    Get element using element_type attribute to locate element.
    Text elements works as ClickText, VerifyText, GetText etc.:

    .. code-block:: robotframework

        ${elem}      GetWebelement          Log In    element_type=text
        ${elem}      GetWebelement          Contact   element_type=text  anchor=Qentinel
        ${elem}      GetWebelement          Contact   parent=div

    Item, Input, Dropdown, Checkbox elements:

    .. code-block:: robotframework

        ${elem}      GetWebelement          Log In    element_type=item
        ${elem}      GetWebelement          Username  element_type=input
        ${elem}      GetWebelement          Country   element_type=dropdown
        ${elem}      GetWebelement          Gender    element_type=checkbox

    All flags are available for using (timeout, anchor, index, visibility, parent, child etc.).
    in same way as you are using those with Pacewords like ClickText/Item, TypeText, Dropdown etc.

    Parameters
    ----------
    locator : str
        Visible text, attribute value or Xpath expression with or without xpath= prefix.
        The equal sign "=" must be escaped with a "\\".
    anchor : int
        Used when element_type is defined. Default=1 (first match)
    element_type : string
        Define element type/preferred searching method
        (available types: text, input, checkbox, item, dropdown).
    timeout : int
        How long we wait element to appear. Default=10 sec
    kwargs :
        |  Accepted kwargs:
        |       Any available for picked searching method.
        |       See interacting with text, item, input etc. elements from
        |       documentation

    Related keywords
    ----------------
    \`ClickElement\`, \`HoverElement\`, \`TypeText\`
    """
    kwargs['index'] = kwargs.get('index', 1)
    kwargs['timeout'] = timeout
    if element_type:
        if element_type.lower() == 'text':
            return text.get_element_by_locator_text(locator, anchor, **kwargs)
        if element_type.lower() == 'item':
            return text.get_item_using_anchor(locator, anchor, **kwargs)
        if element_type.lower() == "dropdown":
            return dropdown.get_dd_elements_from_all_documents(
                locator, anchor, **kwargs)
        if element_type.lower() == "input":
            return input_.get_input_elements_from_all_documents(
                locator, anchor, **kwargs)
        if element_type.lower() == "checkbox":
            return checkbox.get_checkbox_elements_from_all_documents(
                locator, anchor, **kwargs)
    kwargs['element_kw'] = True
    if 'tag' in kwargs:
        web_elements = element.get_visible_elements_from_elements(
            element.get_elements_by_attributes(kwargs.get('tag'), locator,
                                               **kwargs))
    else:
        web_elements = element.get_webelements(locator)
    if web_elements:
        return web_elements
    raise QWebElementNotFoundError('No matching element found')