Links
Links that work, links that open a new tab, and links that return different HTTP status codes.
Status code links
These do not navigate – they call the status code API and show the response here.
Practice tasks
- Click the new-tab link, switch to the new window, assert its title, then switch back.
- Assert the
hrefof the simple link without clicking it. - Click each status button and assert the response text shows the expected status code.
- Reload the page and confirm the third link's text changes – locate it by
idinstead of by text.
Sample automation code
String parent = driver.getWindowHandle();
driver.findElement(By.id("new-tab-link")).click();
for (String handle : driver.getWindowHandles()) {
if (!handle.equals(parent)) driver.switchTo().window(handle);
}
Assert.assertTrue(driver.getTitle().contains("QA Demo"));
driver.close();
driver.switchTo().window(parent);
const [popup] = await Promise.all([
page.waitForEvent('popup'),
page.getByTestId('new-tab-link').click(),
]);
await expect(popup).toHaveTitle(/QA Demo/);
await popup.close();
await page.getByTestId('status-404').click();
await expect(page.getByTestId('link-response')).toContainText('404');