Select is a more common element in a Web form and can be manipulated in selenium2library, such as:
(1) Select by specifying an index
Name: Select from List by Index Arguments: [locator | *indexes]
Selects ' *indexes ' from list identified by ' locator '
(2) Select by specifying text
Name: Select from List by Label Arguments: [locator | *labels]
Selects ' *labels ' from list identified by ' locator '
(3) Select by specifying value
Name: Select from List by Value Arguments: [locator | *values]
Selects ' *values ' from list identified by ' locator '
(4) Multiple items can be selected at the same time
Name: Select from List Arguments: [locator | *items]
Selects ' *items ' from list identified by ' locator '
(5) Select all items
Name: Select all from List Arguments: [Locator]
Selects all values from multi-select list identified by ' ID '.
For quick and easy operation, we implement a method that allows select to automatically assign the maximum index value. Why is the maximum index value not the smallest, such as the first option is "" or "Please select", even if the check is not compliant. So keep looking at the code:
Line 1th: Get_list_items get the Options collection for select
Line 2nd: Get the number of items in the options collection, note that ' $ ' is used here instead of ' @ '
Line 3rd: Calculate the desired index value by calculating
4th Line: Borrowing select from List by index selection by index
At this point, the desired functionality has been achieved, but it is still relatively coarse. If the options have a length of 0 (which is possible), and in practice it is found that if the options are set over the General Assembly there is a noticeable wait process, let's look at the get_list_items function:
You can see that _get_select_list_options and _get_labels_for_options are referenced inside the function.
See _get_select_list_options first.
Here is just a simple judgment and returns the result. Looks like the crux of the problem is the _get_labels_for_options function.
A For loop, although the time complexity is only O (n), but also because the options length of the longer and time-consuming
Select drop-down list maximum index value select from List by Max Index