[英]Exception in thread “main” java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.openqa.selenium.WebElement
I am trying to enter data 'tutorial@gmail.com' at Email field but I'm getting the error mentioned on title/subject. 我试图在“ 电子邮件”字段中输入数据“ tutorial@gmail.com”,但出现标题/主题中提到的错误。
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
((WebElement)driver.findElements(By.name("Email"))).sendKeys("tutorial@gmail.com");
findElements
returns java.util.List<WebElement>
, not WebElement
. findElements
返回java.util.List<WebElement>
,而不是WebElement
。 Maybe you wanted to use findElement
(without s
), which returns a single WebElement
. 也许您想使用
findElement
(不带s
),它返回一个WebElement
。
use driver.findElement
(it will return single element) 使用
driver.findElement
(它将返回单个元素)
instead of 代替
driver.findElements
(It will return list) driver.findElements
(它将返回列表)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.