Assuming that you want two separate lists of elements (one that contains all of the <option>
elements under the <select>
, and one that contains all of the <li>
elements), you will need two Test Objects to identify the individual sets.
1.) First, lets handle the list elements, because the approach can be used for both (however, I will give a better way that’s specific to <select>
elements below). Based on your HTML screenshot, the Test Object could look something like:
Note: I’ve excluded the <li>
that acts as the “header” (I’m assuming you don’t want to include this…).
Then your test code would look like:
List<WebElement> listElements = WebUiCommonHelper.findWebElements(findTestObject('listItemObject'), 30);
2.) Now lets handle the <select>
element. Here’s the Test Object for it, again based on your HTML screenshot:
You could follow the same approach as above to do this, but luckily Selenium has a pretty convenient set of methods that specifically handle <select>
elements. So you could also get a list of all options under the select as follows:
WebElement selectElement = WebUiCommonHelper.findWebElement(findTestObject('selectObject'), 30);
Select select = new Select(selectElement);
List<WebElement> options = select.getOptions();
Again, you could skip the Select class altogether if you want, and follow the same approach as for the list items. If you decided to go this route, your Test Object would look something like:
… and your test code would be the same as for the list items.
Hopefully this is helpful!