Note: If you are new to java and selenium then start with selenium java training videos . We often come across situation when there are multiple elements on a page and we probably like to exercise only a few of them using selenium webdriver. May be just first and last element. For example on a search result page we may like to click on only first and last link and not all. This is when Iterables API comes handy. (By the way I am assuming that you have already completed watching selenium training videos :)). Once we have collection of web element then we can use Iterables to get only first or last element as following - Consider that we fetch collection of element as - List< WebElement > webElements = getDriver().findElements(By. id ( "htmlID" )); Now we can get the first web element from this collection as - WebElement firstElement = Iterables. getFirst (webElements, getDriver().findElement(By. id ( "defaultElement" ))); Herein second
Comments