`package locators;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class csslocators {
public static void main(String[] args) {
WebDriver ch = new ChromeDriver(); // finding element by id
ch.get("https://www.saucedemo.com/");
//using cssSelector id attribute
ch.findElement(By.cssSelector("input[id='user-name']")).sendKeys("standard_user");
ch.findElement(By.cssSelector("input[id='password']")).sendKeys("secret_sauce");
ch.findElement(By.cssSelector("input[id='login-button']")).click();
//using cssSelector name attribute
ch.findElement(By.cssSelector("input[name='user-name']")).sendKeys("standard_user");
ch.findElement(By.cssSelector("input[name='password']")).sendKeys("secret_sauce");
ch.findElement(By.cssSelector("input[name='login-button']")).click();
}
}
`
Top comments (0)