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

Get Selenium Testing Tools Cookbook 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.