Cannot convert from WebElement to List<WebElement>

13,479

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());
Share:
13,479
user1053540
Author by

user1053540

Updated on June 04, 2022

Comments

  • user1053540
    user1053540 almost 2 years
    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...