How to automate links using selenium Webdriver(size, Text, URLs)

Automating links using Selenium WebDriver in Java involves locating link elements on a webpage and interacting with them to perform actions such as clicking, getting attributes, or verifying their presence.

  1. Clicking on a Link:

The most common action with links is to click on them. Here's how you can locate a link and click it using Selenium WebDriver:

  // Locate the link element by its text, ID, XPath, CSS selector, etc.
        WebElement link = driver.findElement(By.linkText("Your Link Text")); // Replace with the text of your link
        
        // Click on the link
        link.click();
        

2. Finding all hyperLinks by anchor tags <a>

List<WebElement> tags= driver.findElements(By.tagName("a"));

System.out.println(tags.size());

for (int i = 0; i < tags.size(); i++) {

System.out.println(tags.get(i).getAttribute("href"));

System.out.println(tags.get(i).getText());

}

driver.close();


To view or add a comment, sign in

More articles by Sambhu Kumar

  • What is Cross-Browser Testing?

    Cross-browser testing is the process of ensuring your web application or website is compatible with different browsers.…

  • Will Chatgpt takeover Software Testing Jobs ??

    While i was using chatgpt i was fascinated about what it could do in helping a person in their learning paths. As…

  • How to write Test Cases ?

    Test Case Definition : Definition – Test case is a step-by-step execution to verify functionality as it is expected…

  • How to write Test Scenario ?

    What is Test Scenario? Test Scenario is high-level documentation. Scenario testing evaluates the performance and…

  • Testing In Production

    What is Software Testing In Production? Testing In Production refers to the practice of conducting various testing…

  • Positive testing and negative testing

    Positive testing and negative testing are two important aspects of software testing that help ensure the reliability…

Insights from the community

Others also viewed

Explore topics