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 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.

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 ...

Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.