page and context, along with any parameters you define:
page and context you receive.
This guide covers Playwright concepts and patterns you’ll use when building automations. If you want to jump straight into code, check out the Playwright basics project in the Intuned TypeScript cookbook or the Playwright basics project in the Python cookbook.
Basics
Navigation
Navigate to a page withgoto():
Wait for page load
After navigation, you may need to wait for the page to fully load. Playwright provideswaitForLoadState():
Wait for URL
Wait for the page to navigate to a specific URL pattern:Create new pages
Intuned initializes one page by default—thepage you receive in your handler. You can create additional pages to run operations in parallel. Both pages run in the same browser on the same machine:
Handle new tabs and popups
When a click opens a new tab (liketarget="_blank" links), capture it with waitForEvent:
popup event:
Finding elements
Locators are the primary way to find elements in Playwright. They’re lazy—not evaluated until you interact with them:CSS vs XPath selectors
CSS selector extensions
When usingpage.locator() with CSS selectors, Playwright adds special pseudo-classes that aren’t available in standard CSS:
Semantic locators
Instead of CSS selectors, Playwright provides methods that find elements by their semantic meaning—role, label, placeholder, or test ID. These are more resilient to markup changes and make your code easier to read:getByRole() — Find by ARIA role and accessible name:
getByText() — Find by visible text:
getByLabel() — Find form fields by their label:
getByPlaceholder() — Find inputs by placeholder text:
getByAltText() — Find images by alt text:
getByTitle() — Find by title attribute:
getByTestId() — Find by data-testid attribute:
Chaining and filtering
When a locator matches multiple elements, narrow it down:Combining locators
Combine locators withand() and or():
Checking element state
Auto-waiting and timeouts
Playwright automatically waits for elements to be ready before performing actions. This auto-waiting happens within a configurable timeout (30 seconds by default). Understanding this helps you write reliable automations without unnecessary delays.What Playwright waits for
When you call an action likeclick() or fill(), Playwright automatically waits until the element is:
This means you rarely need explicit waits before actions:
When you need explicit waits
Use explicit waits when:- Waiting for elements to appear or disappear (loading spinners)
- Waiting for navigation to complete
- Waiting for network requests to finish
Avoid
waitForTimeout() (fixed delays). Waiting for specific elements or network states is more reliable and faster.waitForDomSettled and withNetworkSettledWait helpers.
Configuring timeouts
The timeout controls how long Playwright waits during auto-waiting before throwing an error. The default is 30 seconds. Default timeout — Set for all actions on a page:Extracting data
Text content
Extract the visible text from elements:Attributes
Extract values from HTML attributes likehref, src, data-*:
Bulk extraction
Useall() to get all matching elements as an array, then extract data from each:
all() returns an empty array if no elements match. If you need to wait for elements first, use waitForSelector() before calling all().allTextContents() and allInnerTexts() are convenience methods:
Lists and iteration
Loop through multiple elements usingcount() and nth():
Input values
In rare cases, you may need to read the current value from form inputs—for example, when scraping pre-filled forms or verifying form state:Related Intuned SDK helpers
The Intuned SDK provides helper functions that simplify common data extraction patterns. These handle edge cases and reduce boilerplate:
See the Pagination recipe for multi-page scraping patterns.
Performing actions
Clicking
Double-click
Hover
Force click
Useforce: true when you know the element is there but Playwright’s actionability checks fail (e.g., element is covered by an overlay you want to ignore):
Text input
Type character by character
UsepressSequentially() when a page has special keyboard handling that doesn’t work with fill():
Keyboard actions
Forms
Dropdowns
Checkboxes and radio buttons
Handling dialogs
JavaScript dialogs (alert, confirm, prompt) block the page until handled. Set up a listener before the action that triggers the dialog:
File uploads
File downloads
Listen for thedownload event before triggering the download:
See the download file recipe and upload to S3 recipe.
Complete form filling example
Advanced topics
Working with frames
Frames (iframes) embed a separate webpage inside another. You can’t interact with iframe content directly from the main page—you need to enter the frame context first.frameLocator() to interact with iframe content:
contentFrame():
Shadow DOM: Playwright automatically pierces open shadow DOM—no special handling needed. Your regular locators will find elements inside shadow roots.
Screenshots
Network interception
Intercept and modify network requests usingroute().
Block resources
Speed up automations by blocking unnecessary resources:Modify requests
Executing JavaScript
Usepage.evaluate() when you need to access or manipulate the DOM directly, execute custom JavaScript, or access page-level variables.
Scrolling
DOM manipulation
Pass arguments to evaluate
Making API requests
Playwright provides a built-in API client throughpage.request that shares the browser’s cookies and session:
Cookies and storage
In most cases, you won’t need to manage cookies directly—especially if you use AuthSessions, which handle authentication and session state automatically. The methods below are included for reference when you need low-level control.Read cookies
Set cookies
Clear cookies
Access localStorage and sessionStorage
Drag and drop
Related resources
- Playwright basics (TypeScript) — Cookbook example with TypeScript
- Playwright basics (Python) — Cookbook example with Python
- Intuned SDK overview — Helper functions for common tasks
- Playwright official docs — Full Playwright documentation