0

我正在尝试自动化 gmail 登录。

当我在用户名输入框中输入文本时,使用sendKeys()它会引发异常。

我的代码:

WebElement userName =   driver.findElement(By.id("Email"));
userName.sendKeys("tutorial");

例外:

Error:The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String) at com.gmail.test.Gmaillogin.main(Gmaillogin.java:65)
4

4 回答 4

0

谢谢你们帮助我。我能够解决上述问题。

有效的代码: userName.sendKeys(new String[]{"tutorial"});

有关更多详细信息,请参阅此链接: 使用 selenium WebDriver Java.lang.CharSequence 时出错 Java.lang.CharSequence 无法解决

于 2015-03-15T16:16:58.260 回答
0

它告诉你 sendKeys 方法只获取 CharSequence[] 类型。您必须创建 CharSequence[] 并将您的值插入其中并在 sendKeys 方法中使用它。

有关使用 CharSequence,请参阅此内容:如何将字符串转换为 CharSequence?

于 2015-03-15T07:32:13.893 回答
0

只需在您的项目设置下检查项目语言级别并将其更新为 SDK 默认(IntelliJ,不确定 eclipse),它对我有用。

谢谢

于 2016-01-21T00:37:22.727 回答
-1

SendKeys 方法输入应该是 CharacterSequence 数组,而不是 String。但是在 Java 中,String 等于 CharSequence。所以你可以按照以下方式进行

WebElement userName =   driver.findElement(By.id("Email"));
CharacterSequence[] cs = new String[]{"tutorial"};
userName.sendKeys(cs);
于 2015-03-15T08:09:32.357 回答