0

I want to create the test

  1. Click on element with middle button on the mouse
  2. Verify content of page in new tab

I know how to create new Browser context, but I don't know how to switch to new page. Thank you for any help in advance.

laxsore
  • 143
  • 1
  • 2
  • 9
  • Is [this other question of yours from a few days later](https://stackoverflow.com/q/75211168/) a duplicate of this/trying to solve the same problem? Or could you clarify the difference? – David R Feb 12 '23 at 08:36

1 Answers1

0

you can use the ElementHandle.click() method to simulate a mouse click on a particular element.

const browser = await playwright.chromium.launch();
const page = await browser.newPage();

// Navigate to a web page
await page.goto('https://www.example.com');

// Find the element that links to a new webpage
const linkElement = await page.$('a[href="https://www.example.com/new-page"]');

// Simulate a mouse click on the element
await linkElement.click()
Romano
  • 57
  • 1
  • 8
  • thank you, is there any way to do it without knowing url of new page and creating new page? Ideal would be to detect new page opened and switch to it. But Its something I cannot resolve. – laxsore Jan 20 '23 at 16:18