Checking selected options in dropdowns and lists
In earlier recipes, we saw how to select options in the Dropdown and List controls as well as check what options are available for selection. We also need to verify that the correct options are selected in these controls, either by default or by the user.
In this recipe, we will see how to check options which are selected in a dropdown or list.
Getting ready
This recipe will need the test created from the earlier Automating dropdowns and lists recipe. We will add additional steps for checking the options.
How to do it...
Let's modify the testDropdown()
test method
for checking the options. Add the following highlighted code to the test:
@Test public void testDropdown() { ... //With Select class we can select an option in Dropdown using //Visible Text make.selectByVisibleText("Honda"); assertEquals("Honda", make.getFirstSelectedOption().getText()); //or we can select an option in Dropdown using value attribute make.selectByValue...