In simple Term locator is some unique attribute which we can use to identify the Web Element on a web page in order to perform an action on it.
Any Web Element on a page is created using HTML attribute ( name , type , id , etc ) . we can use their attribute to perform an action on it.
Image by: https://www.besanttechnologies.com/
1) Id locator:
ID is the most common locator used in selenium. Syntax to locate web element using ID is
For example, we can locate 'signup' button of facebook signup page as bellow
driver.findElement(By.id("u_3_s_1I");
driver.findElement(By.name("firstname");
driver.findElement(By.className("inputtext _58mg _5dba _2ph-");
driver.findElement(By.tagName("input");
driver.findElement(By.linkText("terms"));
driver.findElement(By.partialLinkText("terms"));
input[name="firstname"]
//button[@type='submit']