In earlier recipes, we saw how to select options in the dropdown and list controls as well as how to 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 that are selected in a dropdown or list.
This recipe will need the test created from the earlier Automating dropdowns and lists recipe. We will add additional steps for checking the options.
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...