Link

01 Internal Following Links

HomeAbout Us

02 External Following link

Selenium Automation NotesSelenium Complete Course

03 Link are broken

Broken Link Open in New TabBroken Link PageBroken Link

04 Image links

05 Button links

06 Text links

07 Links with query parameters

Create UserNo ContentMovedBad RequestUnauthorizedForbiddenNot FoundDelete Request
Link has responded with staus and status text is

Test case IdTest Case Name
TC01Verify that the accordion expands upon clicking a header
TC02Verify that the accordion collapses upon clicking an expanded header
TC03Verify that only one accordion section is expanded at a time
TC04Verify the content of each accordion section upon expansion
TC05Verify that the accordion retains its state after a page refresh
TC06Verify the responsiveness of the accordion on different screen sizes
TC07Verify that the accordion sections can be navigated using keyboard interactions
TC08Verify the smoothness of the expand/collapse animation
TC09Verify that the accordion headers are accessible via screen readers
TC10Verify that the content within an accordion section is interactable (e.g., links, buttons)
TC11Verify that the accordion collapses when clicking outside the accordion (if applicable)
TC12Verify the accessibility of the accordion for users with disabilities
TC13Verify that the accordion does not overlap with other page elements when expanded
TC14Verify the styling of the accordion headers and content sections
TC15Verify that the accordion sections load correctly without any errors

Insight

  1. accept()
  2. dismiss()
  3. waits()
  4. sendKeys()
  5. switchTo()
  6. getText()

Introduction

Links (<a> tags) are fundamental navigation elements. Automation scenarios include:

  1. Click a link — navigate to another page
  2. Find link by text — locate by visible text
  3. Verify the href — assert the destination URL
  4. Handle new tab — link opens in a new window/tab
  5. Verify broken links — check HTTP status codes

Key Methods Summary

Action Selenium (Java) Playwright (JS) Playwright (Python)
Click link findElement(By.linkText(...)).click() getByRole("link", { name: ... }).click() get_by_role("link", name=...).click()
By partial text By.partialLinkText(...) getByText(...) get_by_text(...)
Get href getAttribute("href") getAttribute("href") get_attribute("href")
New tab switch to window handle context.waitForEvent("page") context.wait_for_event("page")
Current URL getCurrentUrl() page.url() page.url

Selenium (Java)

driver.findElement(By.linkText("Click Me")).click();

Playwright (JS)

await page.getByRole("link", { name: "Click Me" }).click();

Playwright (Python)

page.get_by_role("link", name="Click Me").click()

Selenium (Java)

driver.findElement(By.partialLinkText("Click")).click();

Playwright (JS)

await page.getByText("Click").click();

Playwright (Python)

page.get_by_text("Click").click()

3. Verify href attribute

Selenium (Java)

String href = driver.findElement(By.id("externalLink")).getAttribute("href");
assertTrue(href.contains("qaplayground.com"));

Playwright (JS)

const href = await page.locator("#externalLink").getAttribute("href");
expect(href).toContain("qaplayground.com");

Playwright (Python)

href = page.locator("#externalLink").get_attribute("href")
assert "qaplayground.com" in href

Selenium (Java)

String originalWindow = driver.getWindowHandle();
 
driver.findElement(By.id("newTabLink")).click();
 
// Wait for new window and switch to it
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
 
for (String handle : driver.getWindowHandles()) {
    if (!handle.equals(originalWindow)) {
        driver.switchTo().window(handle);
        break;
    }
}
 
System.out.println("New tab URL: " + driver.getCurrentUrl());
driver.close();
driver.switchTo().window(originalWindow);

Playwright (JS)

const [newPage] = await Promise.all([
  page.context().waitForEvent("page"),
  page.locator("#newTabLink").click(),
]);
await newPage.waitForLoadState();
console.log("New tab URL:", newPage.url());
await newPage.close();

Playwright (Python)

with page.context.expect_page() as new_page_info:
    page.locator("#newTabLink").click()
new_page = new_page_info.value
new_page.wait_for_load_state()
print("New tab URL:", new_page.url)
new_page.close()

5. Verify current URL after navigation

Selenium (Java)

driver.findElement(By.id("homeLink")).click();
assertEquals("https://www.qaplayground.com/", driver.getCurrentUrl());

Playwright (JS)

await page.locator("#homeLink").click();
await expect(page).toHaveURL("https://www.qaplayground.com/");

Playwright (Python)

page.locator("#homeLink").click()
expect(page).to_have_url("https://www.qaplayground.com/")

Selenium (Java)

List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println("Total links: " + links.size());

Playwright (JS)

const count = await page.locator("a").count();
console.log("Total links:", count);

Playwright (Python)

count = page.locator("a").count()
print("Total links:", count)

📄 Also Read: Top 10 Best Automation Practice Website