Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

How to change date in Angular Material Datetime picker using Selenium Webdriver

I want to be able to change the value of a Angular Material Datetime picker using Selenium Webdriver for test automation.

https://www.npmjs.com/package/@angular-material-components/datetime-picker

And I want to know if it can be done using something like Javascript only instead of writing complex code to select "manually" the year, month, etc.

Here's the main part of the HTML generated by Angular :

<mat-form-field ...>
   <input _ngcontent-omb-c17 class="mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-valid ng-touched" id="input_start-date_filter-events" matinput name="startDate" ng-reflect-ngx-mat-datetime-picker="[object Object]" ng-reflect-name="startDate" ng-reflect-model="Tue Jan 12 2021 08:29:00 GMT-0" ng-reflect-id="input_start-date_filter-events" ng-reflect-placeholder="Start date" ng-reflect-readonly="true" aria-haspopup="dialog" placeholder="Start date" aria-invalid="false" aria-required="false">
   <ngx-mat-datetime-picker _ngcontent-omb-c17 ng-reflect-show-seconds="false"></ngx-mat-datetime-picker>
   <span class="mat-form-field-label-wrapper">...</span>
</mat-form-field>

Is there any way to do that?

What I've been trying so far is to change the input value directly using Javascript.

document.getElementById('input_start-date_filter-events').value = new Date(2020,12,1,13,0,0)
document.getElementById('input_start-date_filter-events').value = "2020-12-01 13 h 00"

The string value gets changed visually, but when I submit the form, the changed value isn't taking into consideration.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...