December 2015
Intermediate to advanced
192 pages
3h
English
CHAPTER 2
![]()
Locating Web Elements
As you might have already figured out, to drive an element in a page, we need to find it first. Selenium uses what are called locators to find and match the elements on a web page. There are eight locators in Selenium, as listed in Table 2-1.
Table 2-1. Locators in Selenium
Locator | Example |
|---|---|
ID | FindElement(By.Id("user")) |
Name | FindElement(By.Name("username")) |
Link Text | FindElement(By.LinkText("Login")) |
Partial Link Text | FindElement(By.PartialLinkText("Next")) |
XPath | FindElement(By.Xpath("//div[@id="login"]/input")) |
Tag Name | FindElement(By.TagName("body")) |
Class Name | FindElement(By.ClassName("table")) |
CSS | FindElement(By.CssSelector, ... |
Read now
Unlock full access