Selenium WebDriver-Locators

Selenium WebDriver-Locators

The WebDriver uses the same set of locating strategies like selenium -IDE for specifying the location of the web element.

Each locating strategy has its command in Java to locate the web elements as we are using the WebDriver with Java.

We will use the findElement() and findElements() method for identifying the webelement in the selenium WebDriver.

Where findElement() is used to navigate <HTML> tags, and with the help of locators, it will find the source code and used to identify the single element.

findElement() will throw NoSuchElement exception if the element is not available in the Html source code.

And, findElements() is used to identify the multiple similar elements, and it always returns the list of web elements even though the single and multiple matching elements are found.

findElement(By.locator());

to identify the multiple similar elements

Note: All locators are the methods and start with lower case, and these are also a static method.

Following are the locators which are used in Selenium WebDriver:

  • Id locator
  • Name locator
  • Class name Locator
  • Tag name Locator
  • Link Text Locator
  • Partial link Text Locator
  • XPath locator
  • CSS Selector Locator
locators which are used in Selenium web driver



ADVERTISEMENT
ADVERTISEMENT