Skip to content
CodeKruPro

Right-click (context click) a button

Automation taskEasy-MediumAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

"How do you open a right-click menu?" Use a context click (another name for a right-click) from the actions API. Menus that the page draws itself can then be clicked. The browser's own context menu is outside the page, so Selenium cannot use it. Here you right-click a button that changes its text and read the text before and after.

Right Click (Context Click) Action

Right Click (Context Click)

actions.contextClick(element) simulates a right-click.

On the Buttons page, the right-click button (id="rightClick") changes text to "I was right-clicked!" when right-clicked.

Task:

  1. Navigate to https://testkru.com/Elements/Buttons
  2. Find the rightClick button and print its initial text
  3. Right-click it using the Actions class
  4. Print its text after right-clicking

Expected output:

Before: Right click on me
After: I was right-clicked!