2

Once the page loads, Is there a way to select the option from right click

Example: I am using locator and able to perform right click

await page.getByRole("document").click( { button: "right" }); Now I would like to click on "View Page Source" . Is there an option to do this using Playwright

Basically, the use case is to automate. I expect a different item in the right click which will be useful in automating.

enter image description here

1
  • I'd provide more details. You can always prepend view-source: to your URL rather than right-clicking to view the source, although there's never really any reason for that since Playwright has page.content(). You want to automate the page, not the browser that displays the page. Commented Jul 8, 2024 at 3:05

3 Answers 3

2

This functionality is not supported by Playwright. Seems like a similar issue like this https://github.com/microsoft/playwright-python/issues/676.

Sign up to request clarification or add additional context in comments.

Comments

1

The solution depends on what you're trying to accomplish with the right-click.

If you're trying to retrieve the source of the page

You can get it with page.content() easily, or you can use CDPSession to access Chrome's page.captureSnapshot

If you're trying to right-click a custom context menu which is coded in your app

Playwright doesn't support selecting options from Chrome's context menu, but when you say "I expect a different item," this tells me that your application may have a right-click handler which opens its own in-app context menu instead of Chrome's. In that case, you can locate and left-click on the element that is now visible as a result of your right-click.

Something like

await page.locator(".right-clickable-element").click( { button: "right" });
await page.locator(".app-custom-context-menu-option").click();

Comments

-1

For Java :

   Locator button = page.locator("button_xpath");
   button.click(new Locator.ClickOptions().setButton(MouseButton.RIGHT));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.