Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

datepicker: send keys in Protractor test #10404

Closed
lararogu opened this issue Feb 14, 2017 · 8 comments
Closed

datepicker: send keys in Protractor test #10404

lararogu opened this issue Feb 14, 2017 · 8 comments
Labels
resolution: works as expected The functionality works as designed and documented.

Comments

@lararogu
Copy link

I have an angular app and I would like to test that a user always enters a valid date of birth in a form.I am using a date picker:
(md-datepicker class="inputForm" id="myDate" name="dateField" required md-min-date="minDate" md-max-date="maxDate" > /md-datepicker>

I am trying to use the sendkeys() function in protractor to set a value for the date but it doesn't work:
var today = new Date();
var date = element(by.id('myDate')).sendKeys(today);

When I run the test nothing happens?Any ideas?

@dovydas55
Copy link

Yeah im having a same issue. Would be great to get some feedback on this.

@sudosean
Copy link

sudosean commented May 24, 2017

+1

bower.json :

{
    "name": "my_app",
    "version": "1.4.3",
    "dependencies": {
        "angular": "1.5.8",
        "angular-animate": "1.5.8",
        "angular-aria": "1.5.8",
        "angular-chart.js": "0.10.2",
        "angular-chartist.js": "3.3.13",
        "angular-cookies": "1.5.8",
        "angular-datatables": "0.5.4",
        "angular-native-dragdrop": "1.1.2",
        "jsPlumb": "2.0.5",
        "angular-gantt": "1.2.13",
        "angular-google-maps": "2.3.2",
        "angular-material": "1.1.1",
        "angular-messages": "1.5.8",
        "angular-nvd3": "1.0.7",
        "angular-resource": "1.5.8",
        "angular-sanitize": "1.5.8",
        "angular-timer": "1.3.4",
        "angular-translate": "2.11.0",
        "angular-translate-loader-partial": "2.11.0",
        "angular-ui-calendar": "1.0.1",
        "angular-ui-router": "0.3.0",
        "angular-ui-sortable": "0.14.0",
        "angular-ui-tree": "2.15.0",
        "angular-xeditable": "0.1.12",
        "c3-angular": "1.2.0",
        "css-element-queries": "0.3.2",
        "d3": "3.5.17",
        "datatables-responsive": "2.1.0",
        "highlightjs": "8.9.1",
        "imagesloaded": "4.1.0",
        "jquery": "2.2.4",
        "jqueryui-touch-punch": "*",
        "mobile-detect": "1.3.2",
        "moment": "2.13.0",
        "moment-picker": "0.4.2",
        "moment-range": "2.2.0",
        "nvd3": "1.8.1",
        "ng-flow": "2.7.1",
        "perfect-scrollbar": "0.6.11",
        "Sortable": "1.4.2",
        "textAngular": "1.5.1"
    },
    "devDependencies": {
        "angular-mocks": "1.5.8"
    },
    "resolutions": {
        "angular": "1.5.8",
        "d3": "3.5.14",
        "moment": "2.13.0"
    },
    "overrides": {
        "angular-material": {
            "main": [
                "angular-material.js"
            ]
        },
        "perfect-scrollbar": {
            "main": [
                "css/perfect-scrollbar.css",
                "js/perfect-scrollbar.js"
            ]
        },
        "Sortable": {
            "main": [
                "Sortable.js",
                "ng-sortable.js"
            ]
        },
        "font-awesome": {
            "main": []
        }
    }
} 

@lararogu
Copy link
Author

lararogu commented Jul 10, 2017

Found the solution:

 element.all(by.css('.md-datepicker-input')).get(0).click().sendKeys('10/16/1947');

@mathieub93
Copy link

Just to clear this issue up for everyone getting it.

md-datepicker is a class containing multiple elements, a button and 2 divs in my case.
The button can be interacted with to set a date and the first div has a input field which can be interacted with. The test itself can interact with the md-datepicker itself.

Still fixing this issue for myself as well (by getting the correct xpath from the known location of the md-datepicker).

@jogaga1819daw2
Copy link

jogaga1819daw2 commented Apr 8, 2019

That didn't work for me, instead I used something like this:

element(by.css('#myDate input')).click().clear().sendKeys('10-03-2019');

@Splaktar Splaktar changed the title md-date picker send keys in Protractor test datepicker: send keys in Protractor test Apr 18, 2019
@Splaktar Splaktar added the resolution: works as expected The functionality works as designed and documented. label Apr 18, 2019
@chriskapp
Copy link

For me it worked with the standard date format i.e.

element(by.model('filter.from')).click().sendKeys('2015-06-01');

@ravindranathakila
Copy link

This works for me. Idea is to reach the year selection, navigate to an year and hit enter 3 times.

    element.all(by.xpath('//mat-datepicker-toggle')).get(0).click();

    element.all(by.css('.mat-calendar-period-button')).get(0).sendKeys(protractor.Key.ENTER, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.LEFT, protractor.Key.ENTER, protractor.Key.ENTER, protractor.Key.ENTER);

For your reference, my HTML code, if applicable:

        <mat-form-field fxFlex="100">
          <input required placeholder="{{today}}" matInput [matDatepicker]="picker"
                 (dateInput)="setBirthday('input', $event)" (dateChange)="setBirthday('change',$event); validateBirthday();" (focus)="picker.open();">
          <mat-label>Birthday</mat-label>
          <mat-datepicker-toggle  matSuffix [for]="picker"></mat-datepicker-toggle>
          <mat-datepicker opened #picker></mat-datepicker>
        </mat-form-field>

@Splaktar
Copy link
Member

@ravindranathakila Angular Material and CDK questions are handled here and issues here. This repo is for AngularJS Material.

@angular angular locked as resolved and limited conversation to collaborators Feb 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolution: works as expected The functionality works as designed and documented.
Projects
None yet
Development

No branches or pull requests

8 participants