Using findElement Helper methods

Let's try to create an example where you need to find an element using the CSS selector. This is used by findElementByCssSelector and findElementsByCssSelector.

For example,

using indElementByCssSelector:

Driver.get("http://book.theautomatedtester.co.uk")
WebElement element = ((FindsByCssSelector)driver).findElementByCssSelector("Chapter1");

using findElementsByCssSelector:

driver.get("http://book.theautomatedtester.co.uk")
List<WebElement> elements = ((FindsByCssSelector)driver).findElementsByCssSelector("Chapter1");
Assert.equals(1, elements.size());

Get Learning Selenium Testing Tools - Third Edition 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.