How do I read the option(s) selected in the drop-down
This example demonstrates reading and storing the selected option of the drop-down from the UI.
In the solution shown below, you will read the option(s) selected from the "Select State" drop-down in HICC application using the "storeSomethingSelected" command.
Note: You are reading the value of an element from the UI and initializing to a variable <Variable Name>. The notation to reuse the value of the variable in Worksoft SaaS is ${<Variable Name>}.
Solution:
# | Command | Target | Value |
---|---|---|---|
Read and store the selected option of the drop-down | |||
1 | storeSomethingSelected | //select[@id="dpl_employerInsuranceDropdown"] | SelectedOption |
Print the option that is selected | |||
2 | echo | ${SelectedOption} | |
Tips, Tricks, Gotchas & Best Practices:
- As an alternative to read the selected option(s), you are encouraged to use either of the commands as given below for each option locator:
- Label - storeSelectedLabel or storeSelectedLabels
- Value - storeSelectedValue or storeSelectedValues
- Id - storeSelectedId or storeSelectedIds
- Index - storeSelectedIndex or storeSelectedIndexes
- If you need to validate the available list of options before selecting the option, you can use the commands -
assertSelectOptions, verifySelectOptions or waitForSelectOptions.
- To understand how to select an option, click here.
- 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.