How do I validate if a particular option of the drop-down is NOT selected
This example demonstrates validating if a particular option is NOT selected from the drop-down list.
In the solution shown below, you will validate if the option "Select State" is NOT selected from the "Select State" drop-down in HICC application using the "verifyNotSelectedLabel" command.
Solution:
# | Command | Target | Value | |
---|---|---|---|---|
Select the label 'New Jersey' from the drop-down | ||||
1 | select | //select[@id="dpl_state"] | label=New Jersey | |
Validating that the required/some label is selected by checking "Select State" is not selected | ||||
2 | verifyNotSelectedLabel | //select[@id="dpl_state"] | Select State |
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 - waitForNotSelectedLabel or assertNotSelectedLabel
- Value - verifyNotSelectedValue, assertNotSelectedValue or waitForNotSelectedValue
- Id - verifyNotSelectedId, assertNotSelectedId or waitForNotSelectedId
- Index - verifyNotSelectedIndex, assertNotSelectedIndex or waitForNotSelectedIndex
- 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 need to validate the list of options doesn't have a certain options selected, you can use the commands - assertNotSelectOptions, verifyNotSelectOptions or waitForNotSelectOptions.
- If you want to validate whether some option in a drop-down menu is not selected then you can use the commands - assertNotSomethingSelected, verifyNotSomethingSelected or waitForNotSomethingSelected.