如何使用Selenium/Protractor设置HTML5 type ="date"输入字段(例如在Chrome中)?

Kei*_*h C 10 html5 selenium angularjs protractor

我想更新一些HTML5日期表单字段的日期值(显示为mm/dd/yyyy,只有可修改的数字部分):

<input type="date"/>
Run Code Online (Sandbox Code Playgroud)

在我的Selenium/Protractor测试中.我已尝试使用sendKeys此功能,但(在Chrome上)到目前为止尚未成功.

有没有办法使用sendKeys?还是其他一些方法呢?

小智 7

在Mac上使用带有Protractor的Chrome,以下方法对我有用.

模板(html5)

<input type="date" placeholder="Due Date" ng-model="newLesson.dueDate">
Run Code Online (Sandbox Code Playgroud)

测试

this.newLessonDate = element( by.model('newLesson.dueDate') );
this.newLessonDate.sendKeys('01-30-2015');
Run Code Online (Sandbox Code Playgroud)

在我输入日期格式为'01 -30-2015'之前,我一直收到错误.


Ame*_*mey 0

Selenium 旨在模仿用户交互而不是设置属性。然而,可以使用 Javascript 通过设置类型来更新 DOM 元素

document.getElementById("someID").setAttribute("type","date")
Run Code Online (Sandbox Code Playgroud)