How to get value of a DatePicker Cypress

11,453

Thanks to this post How to get the text input field value to a const and log that value in Cypress.io

I found the answer, it seems I should treat the datepiker input as a text input.

cy.get('input[name="Date"]').invoke('val').then((text) => {
    expect('08/05/2019').to.equal(text);
});
Share:
11,453
Marc
Author by

Marc

QA automation engineer with experience in nodejs, typescript, Java and C#. I worked with selenium, cucumber, specflow, protractor and cypress.

Updated on June 21, 2022

Comments

  • Marc
    Marc almost 2 years

    I am doing some E2E test using cypress and I want to get the date that appears on a DatePicker element from my react app. I tried this but both return an empty string:

    cy.get('input[name="Date"]').invoke('attr', 'value').then((text) => {
        expect('08/05/2019').to.equal(text);
    });
    
    cy.get('input[name="Date"]').invoke(text).then((text) => {
        expect('08/05/2019').to.equal(text);
    });
    

    I would like to get the value of this DatePicker which is always today by default.