简体   繁体   English

无法从WebElement转换为List <WebElement>

[英]Cannot convert from WebElement to List<WebElement>

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... 线程“main”中的异常java.lang.ClassCastException:org.openqa.selenium.remote.RemoteWebElement无法强制转换为java.util.List ...

You should use findElements to find the list of WebElements. 您应该使用findElements来查找WebElements列表。 See API doc here 在此处查看API文档

findElement returns single WebElement whereas findElements is plural and should be the expected one in this case. findElement返回单个 WebElement,而findElements是复数,在这种情况下应该是预期的。

List<WebElement> fields = driver.findElements(By.xpath("//input[@type='text']"));
System.out.println(fields.size());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM