Skip to content

Enhance Get List Items to support returning values or labels #722

Closed

Description

@qitaos

@aaltat
I have a demo website http://demo.robotframework.cn/.
There is a select list, it's html code is:
snipaste20161228_091150

my case is:
snipaste20161228_091354

The keyword get_list_items docstring wrote it will return the values in the select list. But the result is:
snipaste20161228_091336

I want to get the option value for "item1","item2","item3", but it returns the labels "first","second","third".
So I checked the keyword get_list_items source code:
`

def get_list_items(self, locator):
    """Returns the values in the select list identified by `locator`.

    Select list keywords work on both lists and combo boxes. Key attributes for
    select lists are `id` and `name`. See `introduction` for details about
    locating elements.
    """
    select, options = self._get_select_list_options(locator)
    return self._get_labels_for_options(options)

`

It wrote 'returns the values', but it return self._get_labels_for_options(options).

I change the docstring to "Returns the labels", then add a keyword for get_list_values:
`

def get_list_values(self, locator):
    """Returns the values in the select list identified by `locator`.

    Select list keywords work on both lists and combo boxes. Key attributes for
    select lists are `id` and `name`. See `introduction` for details about
    locating elements.
    """
    select, options = self._get_select_list_options(locator)
    return self._get_values_for_options(options)

`

So this is the issue for the pr #721

Activity

  1. aaltat commented on Dec 28, 2016

    @aaltat
    Contributor

    Ah, now I understand, thank you from the explanation.

    Your need is a valid one. The only thing that I am wondering do we need a new keyword for this or would it be better to have one keyword and decide based on argument what to return. Example:

    | ${labels1} = | Get List Items | xpath=//h1 |
    | ${labels2} = | Get List Items | xpath=//h1 | label=${True} |
    | ${values} = | Get List Items | xpath=//h1 | label=${False} |
    | Should Be Equal | ${labels1} | ${labels2} |
    

    There are quite many keywords and I don't like to raise the keyword amount. But I don't feel strongly on the matter, what do you think, or others?

    Also the new functionality must be backed up with tests.

  2. qitaos commented on Dec 30, 2016

    @qitaos
    ContributorAuthor

    I think add argument is fine too.

  3. qitaos commented on Dec 30, 2016

    @qitaos
    ContributorAuthor

    @aaltat I made a new commit for add argument and test cases.

  4. aaltat commented on Dec 30, 2016

    @aaltat
    Contributor

    Thank you. I am busy other stuff for few days, but next year there should be time to take a look.

  5. self-assigned this
    on Dec 31, 2016
  6. added this to the milestone on Dec 31, 2016
  7. changed the title [-]get_list_items return the labels not values[/-] [+]get_list_items return the labels or values[/+] on Jan 11, 2017
  8. aaltat commented on Jan 11, 2017

    @aaltat
    Contributor

    It was decided to make configurable to keyword return values or labels based on a new value argument. The keyword default functionality is backwards compatible.

  9. aaltat commented on Jan 11, 2017

    @aaltat
    Contributor

    Done in #721

  10. changed the title [-]get_list_items return the labels or values[/-] [+]Enhance `Get List Items` to support returning values or labels[/+] on Sep 26, 2017
  11. pekkaklarck commented on Nov 6, 2017

    @pekkaklarck
    Member

    I think values is better name for the optional argument than value. I'll change it while doing cleanup to list related keywords and their docs in general. I'll also add a note that this argument is new in SL 3.0.

  12. added a commit that references this issue on Nov 6, 2017
    900880d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions