Selenium Locators

|
| By Webner

To locate elements in Selenium WebDriver, we can use findElement() for single element and findElements() to locate a list of elements satisfying the search criteria. List of different ways in which both the methods can be used are given below:

driver.findElement(By.id())
driver.findElement(By.name())
driver.findElement(By.className())
driver.findElement(By.tagName())
driver.findElement(By.linkText())
driver.findElement(By.partialLinkText())
driver.findElement(By.cssSelector())
driver.findElement(By.xpath())

For Example, We can use here facebook.com:

Method: ByID
driver.findElement(By.id())

In we give the input email as shown in the below image:

driver.findElement(By.id())

And by using this method Selenium finds the field with id=”email”.
Same procedure is used for the other locators for finding any elements on the page:

0112

 

Leave a Reply

Your email address will not be published. Required fields are marked *