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.
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();