By.cssSelector()
is faster than By.id()
.
The method to find elements using By.id()
actually utilizes xpath:
@Override
public List<WebElement> findElements(SearchContext context) {
if (context instanceof FindsById)
return ((FindsById) context).findElementsById(id);
return ((FindsByXPath) context).findElementsByXPath(".//*[@id = '" + id
+ "']");
}
@Override
public WebElement findElement(SearchContext context) {
if (context instanceof FindsById)
return ((FindsById) context).findElementById(id);
return ((FindsByXPath) context).findElementByXPath(".//*[@id = '" + id
+ "']");
}
Where as By.cssSelector
uses the CSS engine. CSS is faster than xpath, ergo, By.cssSelector
will operate faster than By.id