How to assert all options of a select element at once

Prev Next

This page explains the procedure for retrieving all option texts within a select element (dropdown) and verifying them against an expected list in a single batch.

Procedure

1. Obtain the Locator for the Select Element

  1. During a normal recording, click the target select element and create a step by selecting any option.

  2. Open the created step and click Advanced settings.

  3. Click Change locator.

  4. Copy the displayed Locator and save it somewhere for reference.

2. Prepare the Verification Text (Option List)

  1. Open the target page in your browser and launch the Developer Tools (F12).

  2. In the Elements tab, locate the target select element (<select>).

  3. Right-click the target element and select CopyCopy element.

  4. Paste it into a text editor and extract only the text of the options by removing HTML tags like <option>.

    Format each option into a single text block separated by line breaks (maintain the original order).

    Example of Retrieved HTML

    <select id="pet-select">
                    <option value="">--Please choose an option--</option>
                    <option value="dog">Dog</option>
                    <option value="cat">Cat</option>
                    <option value="hamster">Hamster</option>
                    <option value="parrot">Parrot</option>
                    <option value="spider">Spider</option>
                    <option value="goldfish">Goldfish</option>
    </select>

    Example of Final Text (Format to be pasted as expected value)

    --Please choose an option--
    Dog
    Cat
    Hamster
    Parrot
    Spider
    Goldfish

3. Create and Edit the Bulk Assertion Step

  1. Create a new "Assert text" step at any location on the screen (you will replace the content later).

  2. Open that step and click Advanced Settings.

  3. Configure the following items:

    • Locator: Replace this with the locator you saved in Step 1 of this document.

    • Action: Select Assert text.

    • Match type: Select equals.

    • Text (Expected Value): Paste the list of options, including line breaks, that you prepared in Step 2 of this document.

  4. Click Done to complete.

Important Notes

  • The comparison between the expected value and the actual value is strict and includes line breaks, spaces, and symbols. Even if the text appears the same, the test may fail due to extra whitespace or differences in line breaks.

  • Failures will also occur if the "order" or "count" of the options differs.

  • If the step fails during execution, compare the expected text (line-separated) with the option text on the page to identify differences. Note that some site DOM structures may prevent successful retrieval or comparison.