How do I validate if a particular option of the drop-down is selected
This example demonstrates validating if a particular option is selected from the drop-down list.
In the solution shown below, you will validate if the option "New Jersey" is selected from the "Select State" drop-down in HICC application using the "verifySelectedLabel" command.
Solution:
# | Command | Target | Value | |
---|---|---|---|---|
Select the label 'New Jersey' from the drop-down | ||||
1 | select | //select[@id="dpl_state"] | label=New Jersey | |
Validating if the selected label is "New Jersey" | ||||
2 | verifySelectedLabel | //select[@id="dpl_state"] | New Jersey |
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 - waitForSelectedLabel or assertSelectedLabel
- Value - verifySelectedValue, assertSelectedValue or waitForSelectedValue
- Id - verifySelectedId, assertSelectedId or waitForSelectedId
- Index - verifySelectedIndex, assertSelectedIndex or waitForSelectedIndex
- 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.