Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Right-click an element in Playwright by calling its locator’s click method with button: 'right':
await page.getByText('Item').click({ button: 'right' });
Playwright resolves the locator when the action runs, waits for normal actionability checks, scrolls the element into view, and sends a mouse right-click. The context menu that appears afterward is controlled by your web application, not by Playwright itself.
The basic right-click
The shortest reliable form is a locator action with the right mouse button selected:
Free tools Windows power users keep installed
One-click scans. No signup required.
import { test, expect } from '@playwright/test';
test('opens the item context menu', async ({ page }) => {
await page.goto('https://example.com/items');
await page.getByText('Item').click({ button: 'right' });
await expect(page.getByRole('menu')).toBeVisible();
});
The button option accepts left, right, or middle. Left is the default, so specifying right is what changes the gesture. Use an assertion for the menu, toolbar, dialog, or other result your application is supposed to produce; the click only supplies the input event.
#1 Best Overall
- Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
- Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
- Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
- Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
- Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
Choose a locator that identifies the intended target
Right-clicking the wrong matching element is usually a locator problem, not a mouse problem. Prefer user-facing locators that describe what a person sees or accesses.
Role and accessible name
await page.getByRole('row', { name: 'Item A' }).click({ button: 'right' });
A role locator communicates that the target is a row and narrows it by its accessible name. The same approach works for buttons, list items, tree nodes, and other elements with a meaningful role.
Visible text
await page.getByText('Item').click({ button: 'right' });
Text is useful when it clearly identifies one element. If the label is repeated, add a parent relationship, role, or another user-facing attribute rather than relying on whichever match happens to be first.
Recommended Free Tools
Strictness and uniqueness
Locator actions are strict when a single element is required. If several elements match, Playwright reports the ambiguity instead of silently choosing one. Refine the locator to the actual item under test. Avoid an arbitrary first match unless the test genuinely specifies the first item; such a test can pass while interacting with the wrong row after a layout change.
Right-click at a particular point
Most controls should be clicked at their center. Canvas applications and drawing surfaces are different: the location inside the element can determine which object receives the context menu. Supply a position relative to the element’s padding box:
Rank #2
- The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
- Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
- G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
- Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
- The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere
await page.locator('canvas').click({
button: 'right',
position: { x: 23, y: 32 },
});
The coordinates in this example are illustrative, not universal. Derive them from the interaction your application exposes and keep the test data stable. A position is relative to the selected element, not the entire browser window.
Combine a position with a modifier
Playwright also accepts keyboard modifiers. For example, this sends Shift plus a right-click at a point on a canvas:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →await page.locator('canvas').click({
button: 'right',
modifiers: ['Shift'],
position: { x: 23, y: 32 },
});
Use the modifier only when the application defines a distinct Shift-right-click action. Keep the target locator and coordinates together so a future reader can see exactly which gesture is being tested.
What Playwright waits for before the click
A normal locator click performs actionability checks, including whether the target can be interacted with, and scrolls it into view when needed. This makes the test closer to what a user can do than a raw coordinate injection. If the element detaches while Playwright is carrying out the action, the method throws rather than completing against a stale node.
Prefer the normal action
Let Playwright wait when a menu, table, or canvas is still rendering. If the action fails, inspect why the target was not actionable: the locator may match the wrong element, the element may be hidden or disabled, or the page may still be replacing it.
Rank #3
- Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
- Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
- Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
- Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
- Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
When (and why) to use force
await page.getByRole('row', { name: 'Item A' }).click({
button: 'right',
force: true,
});
force: true bypasses actionability checks. It can be useful when an overlay is intentional and the test specifically needs to dispatch the event, but it can also hide a real usability defect. Use it only when bypassing those checks is part of the scenario; otherwise fix the locator, page state, or application behavior.
Assert the application’s context-menu behavior
Playwright sends the input action; your page decides whether to open a custom menu, suppress the browser menu, select a canvas object, or do nothing. Follow the gesture with an assertion that expresses the expected result:
await page.getByRole('row', { name: 'Item A' }).click({ button: 'right' });
await expect(page.getByRole('menu')).toBeVisible();
await expect(page.getByRole('menuitem', { name: 'Rename' })).toBeVisible();
If the expected menu never appears, first verify that the application actually implements a right-click response for that target. A successful Playwright call does not prove that a context menu was rendered.
Check the target before debugging the menu
- Confirm the locator resolves to the intended element and only one match.
- Use the same role, name, or text a user would identify.
- For a canvas, verify that the position falls inside the intended object.
- Remove
forcewhile diagnosing so actionability failures remain visible.
Complete examples
Context menu for a table row
import { test, expect } from '@playwright/test';
test('row context menu contains row actions', async ({ page }) => {
await page.goto('https://example.com/items');
const row = page.getByRole('row', { name: 'Item A' });
await row.click({ button: 'right' });
await expect(page.getByRole('menu')).toBeVisible();
await expect(page.getByRole('menuitem', { name: 'Rename' })).toBeVisible();
});
Shift-right-click on a canvas
import { test, expect } from '@playwright/test';
test('shift-right-click selects a canvas object', async ({ page }) => {
await page.goto('https://example.com/editor');
await page.locator('canvas').click({
button: 'right',
modifiers: ['Shift'],
position: { x: 23, y: 32 },
});
await expect(page.getByRole('menu')).toBeVisible();
});
Python Playwright
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://example.com/items")
page.get_by_role("row", name="Item A").click(button="right")
browser.close()
The Python API expresses the same gesture with button="right". Add your project’s normal assertion after the click to verify the context-menu result.
Node.js without the test runner
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com/items');
await page.getByText('Item').click({ button: 'right' });
await browser.close();
})();
There is no meaningful cURL equivalent: cURL can make HTTP requests but cannot move a browser pointer, perform Playwright actionability checks, or trigger a page’s client-side context-menu handler.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteRank #4
- Computer mouse for easily navigating a computer interface; click, scroll, and more
- USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
- High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
- 3 buttons offer effortless fingertip control
- Plug-and-go ready for instant use
Troubleshooting right-click failures
“Locator resolved to multiple elements”
Your selector is not unique. Switch to a role plus accessible name, scope the locator to the correct container, or use a more specific visible label. Do not hide the ambiguity with an arbitrary index unless position is the behavior being tested.
The click times out before sending
The target did not become actionable in time. Check that the page reached the expected state, the element is visible and enabled, and no unintended overlay covers it. A locator that points at a stale or replaced node can also fail; locate the element immediately before the action.
The element detaches during the action
A render update replaced the node while Playwright was clicking. Re-locate it after the update and wait for the page state that makes the row or control stable. Avoid caching an element handle across a re-render; locator-based actions are resolved at action time.
The menu does not appear
Playwright may have sent the right-click successfully while the application ignored it. Confirm that the target has a custom context-menu handler and that your assertion looks for the correct role or label. For a canvas, verify the coordinates and try the application manually at the same point.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The click works only with force
That usually indicates a real actionability issue, such as an overlay, hidden element, or disabled control. Treat forced success as a deliberate exception, not proof that a user can perform the gesture. Remove force once the page and locator are corrected.
Best Value
- 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
- 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
- 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
- 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
- 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
The canvas action hits the wrong object
Coordinates are relative to the canvas element’s padding box. Recalculate the point using the application’s coordinate system and keep the viewport and canvas dimensions consistent. A center click on the canvas is not a substitute for a documented object location.
Performance, reliability, and maintenance
- Use semantic locators first: role and text locators communicate intent and are less tied to implementation details.
- Keep coordinates local: use
positiononly when the interaction depends on a point inside an element. - Retain actionability checks: they expose states in which a real user could not right-click.
- Assert the outcome: a passing input call without a menu or state assertion can miss a broken handler.
- Keep modifiers explicit: include
modifiers: ['Shift']only for a behavior your application defines.
Or skip the browser setup
If your goal is a clean visual record of a page before or after an interaction, ScreenshotNeo can capture the URL through one HTTP request. It does not replace Playwright’s right-click action or assert a context menu; it removes the browser-capture setup when you need an image or PDF of the resulting page.
cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
See the ScreenshotNeo documentation for request options. Before capture, it can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo and use the free monthly allowance to capture your test pages.
FAQ
Can I right-click with Playwright’s mouse API?
Yes, but a locator’s click({ button: 'right' }) is usually clearer because it identifies the element and retains actionability behavior. Use a position on the locator when the target point matters.
Does Playwright open the operating system context menu?
Playwright sends the browser input event. Whether a web page opens a custom menu, suppresses the browser menu, or performs another action is determined by the application.
What button value represents a right-click?
Use the string value 'right' in JavaScript or "right" in Python. The other documented values are left and middle.
Frequently Asked Questions
Can I right-click an element found by CSS selector?
Yes. Use page.locator(‘your-selector’).click({ button: ‘right’ }), then prefer a role, text, or other user-facing locator when one uniquely identifies the target.
How do I add Shift to a right-click?
Pass modifiers: [‘Shift’] together with button: ‘right’. You can also provide position when the gesture must land at a specific point.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

