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...
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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.