Articles → SELENIUM → Locate web elements using CSS selector in selenium

Locate web elements using CSS selector in selenium






Prerequisite





Syntax


driver.findElement(By.cssSelector(""))





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://gyansangrah.com/ContactUs.aspx");
		// Locating by link text
		driver.findElement(By.cssSelector("[id=ctl00_cphGyanSangrah_txtEmailID]")).sendKeys("a@a.in");
	}
}



Output



Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, April 04, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250