Articles → SELENIUM → Locate Web Elements By Class Name And Tag Name In Selenium

Locate Web Elements By Class Name And Tag Name In Selenium






Example




Picture showing the logo of the website gyansangrah.com

Click to Enlarge



Picture showing the rendered HTML of the head section of the website

Click to Enlarge



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://gyansangrah.com/Articles.aspx");
		// Locating by link text
		driver.findElement(By.className("Logo")).findElement(By.tagName("a")).click();
	}
}



Output


Picture showing how to Locate web elements by class name and tag name in selenium

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Saturday, April 1, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250