elements / context menu
Advanced element
Context Menu (Right Click)
Practicing context-click actions, custom right-click menus, and alert interception in automated testing frameworks.
Right-Click Zone
#hot-spot
Right-click anywhere inside this box
Triggers a custom context event and confirmation status
- target
- #hot-spot
- status
- #context-out
- expected
- Triggering a contextmenu (right-click) event shows the custom menu and displays status tag.
Code snippets
Python (Selenium)
from selenium.webdriver import ActionChains
box = driver.find_element(By.ID, "hot-spot")
ActionChains(driver).context_click(box).perform()
out = driver.find_element(By.ID, "context-out")
assert out.is_displayed()
assert "Right click event received" in out.textTypeScript (Playwright)
await page.click('#hot-spot', { button: 'right' });
const out = page.locator('#context-out');
await expect(out).toBeVisible();
expect(await out.textContent()).toContain('Right click event received');