通过java发送Selenium - sendKeys不会向输入

时间:2016-07-19 11:38:02

标签: java selenium

我有一个奇怪的情况,我试图通过使用sendKeys键入输入,重新表明特定的字符似乎根本没有在输入中实现。 我想做什么:

webDriver.findElement(By.id("additionalInfo(token_autocompleteSelectInputId)")).sendKeys("(test)");

结果是输入字段现在是:test),缺少的字符是'('。 如果我会尝试

webDriver.findElement(By.id("additionalInfo(token_autocompleteSelectInputId)")).sendKeys("((((((((((")

结果是输入为空。

以前有人遇到过这个问题吗?它发生在应用程序中非常具体的输入上,在html代码中找不到与它相关的任何内容。 提前谢谢。

编辑:我可以手动输入(在输入栏中。

3 个答案:

答案 0 :(得分:0)

也许它是硒的特殊角色,你试过使用转义字符吗?如果它允许的话,就像之前的反斜杠一样。

编辑:我在去年发现了一些关于github的问题报告,不确定他们是否同意不修复它。执行脚本以键入"("似乎是另一种选择。 资料来源:https://github.com/seleniumhq/selenium/issues/674

答案 1 :(得分:0)

首先尝试将密钥声明为字符串

String keyToSend = "(test)";

webDriver.findElement(By.id("additionalInfo(token_autocompleteSelectInputId)")).sendKeys(keyToSend);

答案 2 :(得分:0)

在这种情况下,您应该尝试使用JavascriptExecutor,如下所示: -

WebElement el = webDriver.findElement(By.id("additionalInfo(token_autocompleteSelectInputId)"));

((JavascriptExecutor)webDriver).executeScript("arguments[0].value = arguments[1]", el, "(test)");

希望它有所帮助.. :)