Select drop-down list maximum index value select from List by Max Index

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.