Skip to main content

Blog # 12: Bye-Bye Calendar Headaches: My Playwright Automation Breakthrough


So, I’ve been messing with date pickers lately—you know, those little calendar pop-ups that seem simple until you try automating them. I hit up Test Automation Practice to play around, and I ended up trying three different ways to pick a date using Playwright. One’s super lazy (but effective), one’s like flipping through a calendar, and the last one’s all about dropdowns. Here’s what I did, what worked, and what I thought was kinda cool.


Method 1: The Lazy Direct Fill

First up, I tried the easiest trick in the book—just shove the date right into the input field and call it a day. Here’s the code:

const { test } = require('@playwright/test');

test('Date picker - just fill it', async ({ page }) => {
    // 🚀 Launch the target page
    await page.goto('https://testautomationpractice.blogspot.com/');
    
    // 💥 Directly inject the date like a boss
    await page.locator('#datepicker').fill('02/05/2026');
    
    // 🕶️ Purely theatrical wait (not recommended for production!)
    await page.waitForTimeout(2000); // "Look Ma, the date sticks!"
});

                 

What’s Going On?

I found this #datepicker field, and instead of clicking around, I just typed 02/05/2026 (MM/DD/YYYY) straight into it.

The waitForTimeout was me being nosy—I wanted to watch it sit there for a sec.


My Take

This is the “I’m too tired for this” method. It’s fast, it’s dirty, and it works… until it doesn’t. Some date pickers are picky and won’t let you type—they force you to use the UI. Plus, you’ve gotta know the exact format the site wants (like, is it MM/DD/YYYY or DD-MM-YY?). Still, when it works, it feels like cheating in the best way.


Method 2: Flipping Through the Calendar Like It’s 1999



Next, I tackled the same #datepicker but went full manual—clicking through months like I’m browsing an old desk calendar. Check it out:


test('Date picker - calendar clicker', async ({ page }) => {
    await page.goto('https://testautomationpractice.blogspot.com/');
    
    const day = '04';
    const month = 'March';
    const year = '2026';

    // Open calendar widget
    await page.locator('#datepicker').click();
    
    // Navigate through months
    while (true) {
        const currentMonth = await page.locator('.ui-datepicker-month').textContent();
        const currentYear = await page.locator('.ui-datepicker-year').textContent();

        // Break condition for target month/year
        if (currentMonth === month && currentYear === year) {
            break;
        }
        await page.locator('[data-handler="next"]').click();
    }

    // Select target day
    const dates = page.locator('a.ui-state-default');
    for (const date of await dates.all()) {
        if (await date.textContent() === day) {
            await date.click();
            break;
        }
    }
});


What’s Happening?

Click the field to pop open the calendar.

Loop through months by smashing the "Next" button until I hit March 2026.

Then, hunt down the 04 in the grid and click it.


My Take

This felt old-school—like I was actually using the thing. It’s cool how Playwright lets you grab stuff like .ui-datepicker-month and check it on the fly. But girl, if your date’s years away, you’re clicking "Next" forever. 


Method 3: Dropdowns for the Win



Last up, I hit a different picker (#txtDate) that had dropdowns for months and years. Way less clicking, way more chill. Here’s the code:

test('Calendar dropdown type', async ({ page }) => {
    await page.goto('https://testautomationpractice.blogspot.com/');
    await page.locator('input#txtDate').click();

    const day = '4';
    const month = 'Mar';
    const year = '2028';

    // Select month from dropdown
    const monthDropDown = page.locator('select.ui-datepicker-month');
    await monthDropDown.selectOption(month);

    // Select year from dropdown
    const yearDropDown = page.locator('select.ui-datepicker-year');
    await yearDropDown.selectOption(year);

    // Click target day
    const dates = page.locator('.ui-datepicker-calendar tbody tr td a');
    for (const date of await dates.all()) {
        if (await date.textContent() === day) {
            await date.click();
            break;
        }
    }

    await page.waitForTimeout(3000); // Visual verification
});


What’s Going On?

Click to open the calendar.

Pick Mar from the month dropdown and 2028 from the year dropdown.

Find 4 in the grid and click it.

My Take

This one’s my favorite. No endless clicking—just bam, set the month, set the year, grab the day. It’s like the calendar’s handing you the keys. I threw in a waitForTimeout to watch it work, but in a real test, I’d swap that for something smarter. Feels slick, though—Playwright’s selectOption is a total time-saver.


What I Learned (and Liked)

Direct Fill: Lazy and awesome when it works. Kinda like sneaking past the bouncer.

Clicky Calendar: Fun to code, but slow as heck for far-off dates. Nostalgic vibes, though.

Dropdowns: Fast, clean, and modern. Probably what I’d use in a real project.

I’m hooked on how Playwright makes this stuff doable—grabbing elements, looping through dates, whatever. Next time, I might try handling past dates (clicking "Previous" instead) or maybe test a site that fights back with weird formats. What’s your go-to for date pickers? Hit me up—I’m curious! 

Comments

Popular posts from this blog

Software Testing Heuristics and mnemonics.

Software Testing Heuristics Heuristics are simply experience-based techniques for problem-solving, learning, and discovery. Where an exhaustive search is impractical, heuristic methods are used to speed up the process of finding a satisfactory solution. Examples of this method include using a rule of thumb, an educated guess, an intuitive judgment, or common sense. When you face a problem, you try some solutions that may work. For instance, if you suddenly find your mobile hang, what do you do? You may restart your mobile first. If that doesn’t work, then you may check & update the latest software and uninstall suspicious apps.if that also doesn’t work, then you reset your phone setting ( Factory reset). Most of us try a number of steps to solve our problems. These steps may not always work but we try them because we know that they may work. Following heuristics can apply to absolutely any kind of system with any kind of interface.  1.Abstract  Remove details in a model. S...

Blog # 9: Say Hello to Alerts! Handling Dialog Boxes in Playwright

Alerts and dialogs are common elements in web applications that can interrupt automated test flows if not handled properly. Playwright provides straightforward methods to manage these interruptions, ensuring your tests run smoothly. In this guide, I’ll share how I learned handling three types of dialogs—simple alerts, confirmation boxes, and prompts—using Playwright’s built-in features. Why Handle Dialogs? Dialogs often appear during critical user interactions, such as form submissions, error notifications, or data input requests. If ignored, they can cause tests to freeze or fail. Playwright’s dialog-handling capabilities allow you to: Validate dialog messages. Accept, dismiss, or respond to prompts programmatically. Keep tests resilient and predictable. Let’s explore how to tackle each type of dialog. 1.  Simple Alerts: The One-Way Notification A simple alert is a basic pop-up with an "OK" button. Example Scenario : A basic alert appears, shouting, "I am an alert box!...

A Beginner's Guide to Playwright Testing with JavaScript: 4- A Deep Dive into Playwright Assertions

  Ever spent hours debugging a test only to realize you forgot to check if a button was actually clickable? In web testing, the devil's in the details—and that's where assertions become your best friend. Let's explore how Playwright's assertion library can transform your testing strategy, using the popular The Internet testing playground. Why Assertions Matter Assertions are the backbone of any meaningful test. They're the checkpoints that scream, "This works!" or "Something's broken here!" Playwright's built-in expect library shines when testing real-world scenarios like authentication flows and dynamic content. Let's Start Testing: A Real-World Scenario We'll be testing key features of The Internet playground. Here's our foundation: Now let's add powerful assertions. Validating Content: Is What You See What You Get? 1. Page Titles: Your First Line of Defense Verify you're on the correct page immediately after na...

What is Agile?

                              Recently I did a presentation after almost 20 years at a Bootcamp showcase on Agile. As Agile celebrated its 20th anniversary this year I decided to talk on what Agile is? Below are the few drops from Agile's ocean which I managed to pour during my showcase. What is Agile Software Development? Agile is a time boxed, iterative approach to software delivery that builds software incrementally from the start of the project, instead of trying to deliver it all at once near the end. It works by breaking projects down into little bits of user functionality called user stories, prioritizing them, and then continuously delivering them in short time cycles called iterations.                In iterative development, feature code is designed, developed and tested in repeated cycles. With each iteration, additional features can...

Day 15 Name five different online payment methods.

Most modern online payment services offer easy-to-use, fast and secure ways to pay Here’s a list of some of the most popular online payment services: Digital Wallet ( E wallet) A digital wallet refers to software, an electronic device, or an online service that enables individuals or businesses to make transactions electronically. It stores the payment information of users for different payment modes on various websites.                           PayPal PayPal is one of the most dominant payment methods available today. over 20 million UK shoppers use PayPal each year in the UK and  7 million businesses worldwide use their platform to accept payments. PayPal is an eCommerce payment processing company that allows users to set up a PayPal account and pay a fee for each cash transaction. Many customers prefer to checkout with PayPal because it’s so simple and quick to use. Amazon Pay Amazon Pay is another ...

Risk Storming for Vending Machine

  In the 4th session of Testing Bootcamp Beth Marshall introduced us to a very interesting game of Risk Storming. It's a  collaborative and visual technique for identifying risk and planning the Test Strategy accordingly .You can  use a Test Sphere card deck from Ministry of Testing or go to https://riskstormingonline.com/   Risk Storming takes you through three phases to get the answers. Which quality aspects matter most for your product? What risks could impact these important aspects? How can you test to make sure those risks don’t happen?     Our task was to risk storming to test the Vending Machine . And here is my take on it.                               Quality Aspect Functionality  Does it accept and return both coin and cash correctly? BOUNDARY VALUE TESTING Does it drop the selected product correctly? INTEGRATION TESTING , BUSINESS SCENARIOS , PURPOSE Is the k...

What is Quality

  ✨ What is Quality? Quality means different things to different people. For some, the brand Apple 🍏 is synonymous with quality. For others, it’s difficult to define quality, but surprisingly easy to recognize based on their experiences. A quality product or service is one that satisfies customer needs and meets (or even exceeds!) their expectations. When you receive quality, in whatever form, you're eager to get more. You want to return for another purchase, refer the product to friends, and talk about it publicly. Quality is what we should aim for to ensure returning customers and a strong brand as a company. According to IEEE , quality is defined as “The degree to which a component, system, or process meets specified requirements and/or user/customer needs and expectations.” 📈 👥 Who is Responsible for Software Quality?   Everyone involved in a software project—including the Product Owner , Scrum Master , Developer , Tester , and other stakeholders such as the Business ...