Playwright + TS · Lesson 21 of 36

0/36 done

Module 21: Web Elements

21. Automating Complex UI Widgets & Dynamic Lists

19 minlesson

Try it yourself

Implement parseTableRow:

  1. Accept cells: string[].
  2. Throw an error if cells has fewer than 3 elements.
  3. Return UserRowRecord { id: cells[0], name: cells[1], role: cells[2] }.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

1. Data Tables & Grids

To verify or click an element inside a dynamic table row:

typescript
// Find row containing user email and click its 'Edit' button
const row = page.locator("table tbody tr", { hasText: "jane.doe@example.com" });
await row.getByRole("button", { name: "Edit" }).click();

// Extract all table row texts:
const allNames = await page.locator("table tbody tr td:first-child").allInnerTexts();

2. Auto-Complete / Typeahead Dropdowns

Custom dropdowns that query an API as the user types:

typescript
const searchInput = page.getByPlaceholder("Search countries");
await searchInput.pressSequentially("Jap", { delay: 100 });

// Wait for floating suggestions dropdown and select target
const option = page.getByRole("option", { name: "Japan" });
await option.click();

3. Date Pickers & Calendars

Rather than clicking calendar arrow buttons 50 times, preferred strategies:

  1. Directly fill the input if it is editable:
typescript
await page.getByLabel("Departure Date").fill("2026-10-15");
  1. If read-only, open modal and target precise day:
typescript
await page.getByLabel("Choose date").click();
await page.getByRole("gridcell", { name: "15" }).click();

4. Infinite Scrolling

typescript
async function scrollDownTimes(page: Page, times: number) {
  for (let i = 0; i < times; i++) {
    await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
    await page.waitForTimeout(500); // Wait for next batch of items
  }
}

Key Takeaways & Walkthrough Summary

Modern web applications are filled with complex widgets like data tables, auto-complete dropdowns, date pickers, and infinite scrolling lists. In this lesson, we will learn reliable automation patterns to interact with dynamic web components smoothly and consistently. Let's tackle complex UI elements!

Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

How do I automate sliders with Playwright?

You can fill the slider input if it has an <input type='range'>, or dispatch keyboard ArrowRight / ArrowLeft events to adjust it accurately.

How do I handle rich text editors like TinyMCE or Quill?

Rich text editors often use contenteditable='true' divs or nested iframes. Target the contenteditable container with locator('[contenteditable="true"]').fill('Text').

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

TypeScript
Skip