Browser library - validation of list element's options

Hi,

I would like to build a custom keyword, which validate if the given options exists in some list element.
I Selenium Library it was quite simple, because of the keyword “Get List Items”.
In Browser library exists only “Get Select Options” keyword, which returns a list of dictionaries from all list options.

Example validation keyword:
${dropdownElements} = Get Select Options ${listObject} validate [v[“label”] for v in value] in [“label1”, “label2”, “label3”]
works only, if the labels are sorted (as indexed in dictionary) and all of the list labels are given.

Example result from loop:

entry {
label: “label1”
selected: true
}
entry {
value: “Non Prod”
label: “label2”
index: 1
}
entry {
value: “Not Possible”
label: “label3”
index: 2
}

How could I make this validation more universal? I want to check if “[v[“label”] for v in value]” contains, for example, [“label3”, “label1”, “label2”] or [“label3”, “label1”]. Independent from sorting, giving not all existing options.

I have created an own validation keyword using “Get Text”, collecting and validating the text (labels) from the list options, but it’s quite expanded and want to try get something more compacted.

I will be grateful for any help and tips!

Hello,

First, is it not possible to use Seleniumlibrary, even called/loaded and used only in one file?

Apart from this, the Get Text seems anyway a good solution, as long as you loop on it.
You could get the values by targeting the locator of the list (1), then pass also as arguments two lists, one for expected values (2), the other for not expected ones (3).

Then loop on those lists with should contain, and should not contain from Built-in library against the first list (1).

Regards.
Charlie

Hi @kradek92,

You can do something like this:

${dropdownElements}=    Get Select Options    ${listObject}
@{label_list}=    Evaluate    [v[“label”] for v in ${dropdownElements}]
Should Contain    ${label_list}    label3
Should Contain    ${label_list}    label1

Basically this part ([v[“label”] for v in ${dropdownElements}]) is python code, so we can run that anywhere using Evaluate and it should give us a list, then with that list we can do all the validations we need.

you can also sort the list if you want:

@{label_list}=    Set Variable    @{label_list.sort()}

You can also wrap the first 2 lines with the sort in your own keyword something like Get Select Labels if you have many of these select options to validate.

Dave.