I have a datepicker calendar as below [![enter image description here][1]][1] To select a particular date I am using this code
JavaScript
x
4
1
cy.get('.fa-calendar').click();
2
cy.get('[label="select-year"]').select(2023);
3
cy.get('[label="select-month"]').select('Jan');
4
Now to select the date I am using below approach which is working fine
JavaScript
1
4
1
cy.get('.ngb-dp-month>ng-star-inserted:nth-of-type(1)').within(()=>{
2
cy.get('.ngb-dp-day').contains('10').click();
3
})
4
but I don’t wanted to use nth-of-type(1)
because it will cause issue in future I tried this approach whic didn’t work
JavaScript
1
4
1
cy.contains('January 2023').within(()=>{
2
cy.get('.ngb-dp-day').contains('10').click();
3
});
4
Can you folks help me resolving the issue also any other alternative is also welcome [1]: https://i.stack.imgur.com/38XyO.jpg
Advertisement
Answer
Basically, you just need to combine the two different ways you tried: cy.get('.ngb-dp-month')
and cy.contains('January 2023')
This should work
JavaScript
1
5
1
cy.contains('.ngb-dp-month', 'January 2023').within(()=> {
2
cy.contains('.ngb-dp-day', '10')
3
.click()
4
})
5