Articles → SELENIUM → Locate Web Element Through Link Text In Selenium

Locate Web Element Through Link Text In Selenium






Scenario




  1. Go to google.com
  2. Search the link with the text ‘Images’
  3. Click on it.

Syntax


driver.findElement(By.linkText("link_text"))





Example


package com.FirstSeleniumProject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class MyClass {

	public static void main(String[] args) {
		WebDriver driver;
		String service = "IEDriverServer path";
		System.setProperty("webdriver.ie.driver", service);
		driver = new InternetExplorerDriver();
		driver.get("http://google.com/");
		// Locating by link text
		driver.findElement(By.linkText("Images")).click();;
	}

}



Output


Picture showing the output of the Locate web element through link text in selenium
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, March 30, 2017

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250