Selenium webElement.clear() 不适用于 phantomJS 但适用于 Firefox

Selenium webElement.clear() doesn't work with phantomJS but yes with Firefox

我正在尝试使用 PhantomJS 作为浏览器来进行 selenium 测试,但输入有问题。 此输入是日历(不是日期类型,是文本,但由 JavaScript 修改)。

首先,我使用 FirefoxDriver 得到了这个并且运行良好:

webElement.Clear();
webElement.SendKeys(date);

但是,使用 PhantomJSDriver 会跳出一个异常:

{"errorMessage":"Element must be user-editable in order to clear it.","request":{"headers":{"Accept":"application/json, image/png","Connection":"Close","Content-Length":"0","Content-Type":"application/json;charset=utf-8","Host":"localhost:53291"},"httpVersion":"1.1","method":"POST","post":"","url":"/clear","urlParsed":{"anchor":"","query":"","file":"clear","directory":"/","path":"/clear","relative":"/clear","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/clear","queryKey":{},"chunks":["clear"]},"urlOriginal":"/session/a1e4cdb0-b901-11e4-befc-c3b28b46e8f3/element/%3Awdc%3A1424437741971/clear"}}

非常无关紧要,因为在 Firefox 中运行完美, 我该怎么做才能发送数据?

我也尝试在不清除的情况下发送此数据,但默认值为 20/02/2015,当我发送内容时,只需在当前文本后添加:20/02/201530/03/2015 并且不会'不工作。

属性.text没有setter,getAttribute()也一样。

谢谢大家,

伊万.

@edit1: html

<input type="text" aria-haspopup="true" title="" value="20/02/2015" name="id0" id="id0" class="bg datetime hasDatepicker">

最后我找到了如何做到这一点,可能不是最好的方法,但在我的情况下有效。

我通过 JavaScript 使用 javascriptExecutor

发送数据

((IJavaScriptExecutor)_driver).ExecuteScript("document.getElementById('id0').value='" + date+ "'");