Handling Links

Manual action on Link elements

  • Click to redirect
  • Check display status
  • Check enabled status
  • Return element name

Selenium WebDriver Steps

package HandlingElementsInSelenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class HandlingWebLinks {

	public static void main(String[] args) {
		
	System.setProperty("webdriver.chrome.driver", "F:\\chromedriver.exe");
	WebDriver driver = new ChromeDriver();
	driver.manage().window().maximize();
	driver.get("https://www.google.com/");
	
	WebElement gmailLink = driver.findElement(By.linkText("Gmail"));
	
	//Check display status
		boolean status = gmailLink.isDisplayed();
		System.out.println("Link is present :- "+status);
		
	//Check enable status
		status = gmailLink.isEnabled();
		System.out.println("Link is enabled :- "+status);
		
	//Return Link name
		String linkName = gmailLink.getText();
		System.out.println("Link name is :- "+linkName);
		
	//Click
		gmailLink.click();
				
	driver.close();

	}
}

Next

Leave a comment

Design a site like this with WordPress.com
Get started