Rayrun
← Back to Discord Forum

Filling date picker.

expire_date = (datetime.now() + timedelta(days=365*2)).strftime("%d/%m/%Y %H:%M")
        page.fill("#LinkExpireDate", expire_date)
        page.wait_for_timeout(10000)

I tried this but the results are in the attachment. It doesn't save the right date, it save today's date. Thanks.

This thread is trying to answer question "Why is the script saving the current date instead of a date two years from now?"

0 replies

Answer

Saving a Future Date in Playwright

If you're wondering why your script is saving the current date instead of a future date, it's likely because there's no code telling it to do otherwise. To save a date two years from now, you need to add code that calculates this.

Here's how you can do it using TypeScript:

// Get current date
const currentDate = new Date();

// Add two years
const futureDate = new Date(currentDate.getFullYear() + 2, currentDate.getMonth(), currentDate.getDate());

console.log(futureDate);

In this code, we're using JavaScript's Date object to get the current date. Then, we're adding two years to the current date by modifying the year component. We do this using the getFullYear() method. Finally, we create a new Date object with the modified year value.

Remember, without more information about your script, it's hard to provide a solution tailored to your situation. If you can provide more details about your script and where you expect a future date value, I can help you find a suitable solution.

For more tips on writing efficient Playwright test scripts, check out this blog post.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.