obihobit
obihobit

Reputation: 1

Picking a date from date picker popup

I'm new to Playwright but I've had some experience with automation and I'm trying to select a date in a project I'm working on (C#), but I just can't get it to work. Form field can't be just filled with FillAsync, it has to be selected from the popup, but my every attempt to hit that locator has failed.

Date picker Date element

So far I've managed to click on the calendar button to open the date picker with this line of code:

await Page.ClickAsync("//input[@placeholder='Start date']");

but for the life of me I can't pick any date. I tried bunch of variations of this line of code:

await Page.ClickAsync("//td[@class='ng-tns-c130-2 ng-star-inserted'][text()='28']");

But so far no luck. Do you have any suggestions how to do it?

Upvotes: 0

Views: 863

Answers (2)

Vishal Aggarwal
Vishal Aggarwal

Reputation: 4207

How about this simply to select current date:

//td[contains(@class,"today")]

Upvotes: 0

Josh Heaps
Josh Heaps

Reputation: 296

If you're having problems with a click, I almost always recommend javascript. Here is a quick code snip that will use javascript to click on an element given the ID

await Page.EvaluateAsync("document.getElementById(\"id\").click();");

Upvotes: 0

Related Questions