Imagine that your test requires you to type something into each of the input boxes on the page, or if you needed to check how many buttons were on the page.
In this scenario, the findElements
method call will be extremely useful and we can tell the driver to search by tagName
to find all of the items on the page.
Create a new test to access http://book.theautomatedtester.co.uk/chapter2.
Find all elements that are an input.
Assert whether the list size is five.
Run your test. It should appear as follows:
@Test public void shouldLoadChapter2AndFindAllInputElements(){ driver.get("http://book.theautoamtedtester.co.uk"); List<WebElement> inputs = driver.findElements(By.tagName("input")); Assert.assertEquals("Should be 5",5,inputs.size()); }