Comments for Select Options By

Topic for comments about Browser library keyword Select Options By

Is there a simple method to select ALL options when you may not know what they even are or how many there may be?

Hi Scott,

I don’t believe there is an option for that but it’s quite easy for you to implement one by combining Get Element Count with a for loop wrapped around Select Options By using the select by index option.

here’s an example, with html like this:

<select multiple id="myselect">
  <option value="syyn34">random value</option>
  <option value="yhs682">another item</option>
  <option value="lidy02">Other than this</option>
</select>

You should be able to do something like this:

${count}=    Get Element Count    //select[@id="myselect"]/option
FOR    ${i}    IN RANGE    ${count}
    Select Options By    id=myselect    ${i}
END

You could then take it a step further like this:

*** Keywords ***
Select All Options
    [Attributes]    ${id}
    ${count}=    Get Element Count    //select[@id="${id}"]/option
    FOR    ${i}    IN RANGE    ${count}
        Select Options By    id=${id}    ${i}
    END

Hope that helps,

Dave.

Thanks you @damies13

I was about to start doing something like that before I posted the question… but I like your approach much more than what I was first thinking involving a List.

I wasn’t sure if I was missing something simple that is natively available on the Keyword, as I’ve just started trying to use the Browser library a couple days ago and was trying to see how much effort it would take to ‘convert’ from using Selenium Library.

@mkorpela ,
I am trying to capture the alerts , popups that appear dynamically while running the test suite . Please can you suggest me a better way to do this with Robot framework ? .
Thanks
Fredrick