HOW TO HANDLE MULTIPLE TABS USING SELENIUM PLAYWRIGHT AND CYPRESS | TEST AUTOMATION| QA SDET

Опубликовано: 23 Июль 2026
на канале: Viplove QA - SDET
1,125
like

Window/Tab Switching

Selenium:

Use getWindowHandles() to get all open tabs/windows and switch using switchTo().window(handle).


Set String handles = driver.getWindowHandles();
for (String h : handles) {
driver.switchTo().window(h);
}

Playwright:

Use context.waitForEvent('page') to capture the new tab as a Page object.


const [newPage] = await Promise.all([
context.waitForEvent('page'),
page.click('a[target=_blank]')
]);
await newPage.bringToFront();

Cypress:

No direct support for multiple tabs. Stub window.open or force the link to open in the same tab.


cy.window().then((win) = {
cy.stub(win, 'open').as('tabOpen');
});
cy.get('a').click();
cy.get('@tabOpen').should('be.called');