Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Selenium Locators in Selenium Java
// Sign In Link by ID
driver.findElement(By.id("sign-in"));
// Sign In Button by Name
driver.findElement(By.name("commit"));
// Home Link by Class Name
driver.findElement(By.className("nav-item"));
// Sign In Link by Tag Name
driver.findElement(By.tagName("a"));
// Sign In Link by CSS
driver.findElement(By.cssSelector("a[data-test=sign-in]"));
// Sign In Link by XPath
driver.findElement(By.xpath("//a[@data-test='sign-in']"));
// Sign In Link by Link Text
driver.findElement(By.linkText("Sign in"));
// Sign In Link by Partial Link Text
driver.findElement(By.partialLinkText("Sign"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment