How to check page in new tab in Playwright (C#)

363 views Asked by At

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.

1

There are 1 answers

1
Romano On

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()