Playwright Cheatsheet
A quick reference guide to commonly used Playwright commands for browser automation and testing.
Browser Start and Close
| Start a Chromium browser instance |
| Start a Chrome browser instance |
| Start a Microsoft Edge browser instance |
| Start a Firefox browser instance |
| Start a WebKit browser instance |
| Close the browser instance |
Context Management
| Create a new browser context |
| Close the browser context |
Page / Tab Management
| Open a new page / tab |
| Wait for a new page / tab to be opened (e.g. from clicking a link with target="_blank") |
| List all pages |
| Make the page / tab the active one |
| Close the current page / tab |
| Check if the page / tab is closed |
Page Information
| Get the current page URL |
| Get the current page title |
Page Assertions
Requires import { expect } from '@playwright/test'
| Assert the url of a page equals a specific value |
| Assert the url of a page using a function |
| Assert the title of a page equals a specific value |
Navigation
| Navigate to a URL |
| Reload the current page |
| Navigate back in history |
| Navigate forward in history |
Element Selection
| Select an element using a CSS selector |
| Select an element containing specific text |
| Select a form element by its associated label text |
| Select an element by its ARIA role and name |
| Select an input element by its placeholder text |
| Select an image element by its alt text |
| Select an element by its title attribute |
| Select an element by its |
Waiting for Element States
| Wait for an element to be present in the DOM |
| Wait for an element to be visible on the page |
| Wait for an element to be visible on the page with a custom timeout |
| Wait for an element to be hidden or removed from the page |
| Wait for an element to be removed from the DOM |
Element State
| Get the text content of an element |
| Get the inner text of an element |
| Get the inner HTML of an element |
| Get the outer HTML of an element |
| Get the value of a specific attribute of an element |
| Get the value of an input element |
| Get the bounding box of an element |
| Check if an element is visible on the page |
| Check if an element is hidden on the page |
| Check if an element is enabled |
| Check if an element is disabled |
| Check if a checkbox or radio button is checked |
| Check if an element is editable |
Element Assertions
Requires import { expect } from '@playwright/test'
| Assert that an element is attached to the DOM |
| Assert that an element is visible on the page |
| Assert that an element is hidden on the page |
| Assert that an element contains specific text (case insensitive) |
| Assert that an element contains specific text (case insensitive) |
| Assert that an element does not contain specific text |
| Assert that an input element has a specific value |
| Assert that a multi-select element has specific selected values |
| Assert that an element contains a specific CSS class |
| Assert that an element does not contain a specific CSS class |
| Assert that an element has a specific CSS style |
| Assert that an element has a specific attribute with a specific value |
| Assert that an element has a specific attribute with a specific value |
| Assert that a checkbox or radio button is checked |
| Assert that a checkbox or radio button is not checked |
| Assert that an element is enabled |
| Assert that an element is disabled |
| Assert that an element is focused |
Element Click / Hover / Drag and Drop
| Click on an element |
| Right click on an element |
| Double click on an element |
| Click on an element with keyboard modifiers (e.g. Ctrl, Shift) |
| Click on an element at specific coordinates |
| Hover over an element |
| Hover over an element at specific coordinates relative to top-left of the element |
| Drag an element and drop it onto another element |
| Drag an element and drop it onto another element with an offset |
Mouse
| Move the mouse to specific coordinates relative to viewport |
| Click the mouse at the current position |
| Click the mouse at specific coordinates relative to viewport |
| Click the mouse with a specific button (e.g. right button) at specific coordinates relative to viewport |
| Double-click the mouse at specific coordinates relative to viewport |
| Press the mouse button down |
| Press the mouse button down with options |
| Release the mouse button |
| Release the mouse button with options |
| Scroll the mouse wheel by deltaX and deltaY |
Form Input Element Interactions
| Fill a text input |
| Use |
| Use |
| Use |
| Clear a text input |
| Check a checkbox |
| Uncheck a checkbox |
| Select an option in a dropdown by label or value |
| Select multiple options in a multi-select dropdown |
Keyboard
| Press a key |
| Press a key chord (e.g. Control+A to select all text) |
| Type text with delay between each key |
| Type text with delay between each key |
| Hold a key down (without releasing it) |
| Release a key that is being held down |
Element Interactions
| Focus an element |
| Remove focus from an element |
| Scroll an element into view if it is not already visible |
| Focuses on an element and selects all its text content |
File Upload and Download
| Upload a single file to a file input element |
| Upload multiple files to a file input element |
| Upload multiple files from memory to a file input element |
| Clear a file input element |
| Download a file and save it to disk |
Evaluate javascript
| Evaluate JavaScript in the page context as a string |
| Evaluate JavaScript in the page context as a function |
| Evaluate JavaScript in the page context with arguments |
Alert / Prompt / Confirmation Dialogs
| Listen for an alert dialog and accept it |
| Listen for a prompt dialog and enter text before accepting it |
| Listen for a confirmation dialog and dismiss it |
| Listen for an alert dialog and get its message |
Cookies
| Get all cookies for the current context |
| Add cookies to the current context |
| Clear all cookies in the current context |
| Clear a cookie with a specific name |
| Clear cookies for a specific domain |
Viewport / Window Size
| Get the current viewport size |
| Set the viewport size |
Screenshots
| Take a screenshot of a specific element |
| Take a screenshot of the current viewport |
| Take a screenshot of the entire page |