Selenium locating elements



VariationDescriptionSample
By.classNamefinds elements based on the value of the "class" attributefindElement(By.className("someClassName"))
By.cssSelectorfinds elements based on the driver's underlying CSS Selector enginefindElement(By.cssSelector("input#email"))
By.idlocates elements by the value of their "id" attributefindElement(By.id("someId"))  
By.linkTextfinds a link element by the exact text it displaysfindElement(By.linkText("REGISTRATION"))  
By.namelocates elements by the value of the "name" attributefindElement(By.name("someName"))  
By.partialLinkTextlocates elements that contain the given link textfindElement(By.partialLinkText("REG"))  
By.tagNamelocates elements by their tag namefindElement(By.tagName("div"))  
By.xpathlocates elements via XPathfindElement(By.xpath("//html/body/div/table/tbody/tr/td[2]/table/ tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[3]/ form/table/tbody/tr[5]"))

Comments