我正在尝试使用PhantomJS作为浏览器进行硒测试,但我输入有问题。 此输入是日历(不是类型日期,是文本,但是由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
没有设置器,getAttribute()
也是如此。
感谢所有人,
伊凡。
@ edit1:html
<input type="text" aria-haspopup="true" title="" value="20/02/2015" name="id0" id="id0" class="bg datetime hasDatepicker">
答案 0 :(得分:0)
最后我发现如何做到这一点,可能不是最好的方法,但在我的情况下有效。
我使用javascriptExecutor
通过JavaScript发送数据 ((IJavaScriptExecutor)_driver).ExecuteScript("document.getElementById('id0').value='" + date+ "'");