Reputation: 39
List<WebElement> fields = (List<WebElement>) driver.findElement(By.xpath("//input[@type='text']"));
System.out.println(fields.size());
This my Code and the error is
Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to java.util.List...
Upvotes: 2
Views: 15471
Reputation: 16201
You should use findElements
to find the list of WebElements. See API doc here
findElement
returns single WebElement whereas findElements
is plural and should be the expected one in this case.
List<WebElement> fields = driver.findElements(By.xpath("//input[@type='text']"));
System.out.println(fields.size());
Upvotes: 11