Switch to v2 to see which selectors break.
Add to Chrome

Window handles practice website

Practice switching windows: a link that opens a new tab, and a pop-up window that sends a reply back to this page. Open a shop product page

New tab

Built to break

Open

Pop-up windowType a reply in the pop-up and send it back.

Built well

Built to break

Open help window
How to locate Windows and tabs

A new window is a new place to look

Every tab and pop-up is its own window with its own document. A test keeps looking at the window it started in until it switches, so after clicking a link that opens a new tab, every locator still searches the old page.

Each tool models this differently. Selenium tracks windows by handle: wait for a second handle, switch to it, do the work, and switch back. Playwright treats each tab as a separate page object you get from an event. Cypress runs inside a single tab and cannot drive a second one, so tests check the link’s target and open it in the same tab, or stub window.open.

How the window opens matters too. A real link with target="_blank" can be inspected before clicking. The fragile form opens its tab from script on a span, so there is no link and no href to check, and its text changes on v2.

Pop-ups that talk back to their opener, as payment and sign-in windows do, need the test to finish in the pop-up and then return to the first window before asserting the result.

What a stable locator looks like

Wait for the new window explicitly, work in it, then return to the original window before the next step. Prefer a real link you can inspect; for script-opened pop-ups, find the button by name and wait for the window to exist.

// New tab from a target="_blank" link
const [tab] = await Promise.all([
  page.context().waitForEvent('page'),
  page.getByTestId('new-tab-link').click(),
]);
await expect(tab).toHaveURL(/\/practice\/shop\/product/);
await tab.close();

// Pop-up that replies to this page
const [popup] = await Promise.all([
  page.waitForEvent('popup'),
  page.getByTestId('popup-button').click(),
]);
await popup.getByLabel('Reply').fill('All good');
await popup.getByTestId('popup-send').click();
await expect(page.getByTestId('popup-reply')).toHaveText('Help window says: All good');

In a real workflow

Every shop product page has an “Open in new tab” link and a fragile “Chat with us” button that opens the help pop-up.

COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the windows and tabs above with it and compare its pick with yours.

Add to Chrome