Home >>Selenium Tutorial >Selenium WebDriver - Locating Strategies
Just like Selenium IDE, WebDriver uses the same collection of locating techniques for determining position of a specific web element.
Because, we are using WebDriver with java; each locating technique has its own command in Java to locate the web element.
Using findElement() and findElements() methods provided by WebDriver and WebElement class, locating elements in Selenium WebDriver is executed.
Method | Syntax | Description |
---|---|---|
By ID | driver.findElement(By.id (<element ID>)) | It is used to Locates an element using the ID attribute |
By name | driver.findElement(By.name (<element name>)) | It is used to Locates an element using the Name attribute |
By class name | driver.findElement(By.className (<element class>)) | It is used to Locates an element using the Class attribute |
By tag name | driver.findElement(By.tagName (<htmltagname>)) | It is used to Locates an element using the HTML tag |
By link text | driver.findElement(By.linkText (<linktext>)) | It is used to Locates a link using link text |
By partial link text | driver.findElement(By.partialLinkText (<linktext>)) | It is used to Locates a link using the link's partial text |
By CSS | driver.findElement(By.cssSelector (<css selector>)) | It is used to Locates an element using the CSS selector |
By XPath | driver.findElement(By.xpath (<xpath>)) | It is used to Locates an element using XPath query |