Element locator in selenium
Element locators in selenium plays very crucial role. Selenium find element using element locator. Selenium webdriver is automation testing tool which interacts directly with UI elements same as real user interacts with them.
Selenium do not have any built in feature to locate element itself. To perform any action on UI element, We have to provide element locator in selenium test script. Selenium will find that element from page based on provided element locator and then it will perform given action on it.
Let’s consider practical example. You have a login page with 3 different elements User ID textbox, Password textbox and Login button. Now you want to write a selenium test script for user login. Your selenium test script will look like below.
- ID – Locate element by ID of element.
- Name – Locate element by Name of element.
- ClassName – Locate element by class name of element.
- linkText – Locate element by link text of element.
- partialLinkText – Locate element by partial link text of element.
- cssSelectors – Locate element by CSS selector of element.
- XPath – Locate element by XPath of element.
- tagName – Locate element by tag name of element.