How do I validate the selected options of a multi-select drop-down
This example demonstrates selecting multiple options from a multi-select drop-down and validating the selected options.
In the solution shown below, you will validate all the options selected from the "Select State" drop-down in HICC application using the "assertSelectedLabels" command.
Solution:
# | Command | Target | Value |
---|---|---|---|
Selecting first option | |||
1 | select | //select[@id="dpl_state"] | label=New Jersey |
Selecting second option | |||
2 | select | //select[@id="dpl_state"] | label=California |
Selecting third option | |||
3 | select | //select[@id="dpl_state"] | label=New York |
Validate all the selected options | |||
4 | assertSelectedLabels | //select[@id="dpl_state"] | New Jersey,California,New York |
Note: The multi-select drop-down is currently not available in HICC, hence if you execute the above solution, it will not work.
Tips, Tricks, Gotchas & Best Practices:
- To understand how to select an option, click here.
- As an alternative to validating the selected option, you are encouraged to use either of the commands as given below for each option locator:
- Label - waitForSelectedLabels or verifySelectedLabels
- Value - verifySelectedValues, assertSelectedValues or waitForSelectedValues
- Id - verifySelectedIds, assertSelectedIds or waitForSelectedIds
- Index - verifySelectedIndexes, assertSelectedIndexes or waitForSelectedIndexes
- If you need to validate the available list of options before selecting the option, you can use the commands -
assertSelectOptions, verifySelectOptions or waitForSelectOptions.
- If you want to validate whether some option in a drop-down menu is selected or not then you can use the commands - assertSomethingSelected, verifySomethingSelected or waitForSomethingSelected.