How to count elements in search result and fail the step if max results is counted?

PLS have a look at this post.

You do not need any “loop” statements. You just need to know the size of the List<WebElement> returned by WebUI.findWebElements keyword.