We have Locators in Selenium RC and Webdriver to identify the web elements. Some useful locators are mentioned below:
How to find ID, Link text and Name of Web Element?
Step 1: Move and put the cursor of the mouse on the web-element.
Step 2: Right Click, so the action list open.
Step 3: Find the Inspect Element or Inspect option and Click on it.
For example: If you want to find the locator ID of Search button of Google Search:
How to find CSS Locator?
If ID and Name are not available or not working then we can go for CSS (Cascade Style Sheet). It is a combination of “tag name.class name”.
Syntax: Selenium.click (“css = tagname.classname”);
Example: Selenium.click (“css = td.cal to day.tcalselected”);
Note: If the classname is having space then we will replace the space with dot (.).
X – Path:
It will identify the elements by using tag name with attributes.
Syntax: “//tagname[@attribute (s)]”
It is of two types:
- Relative X-Path
- Absolute X-Path
It will identify the elements with Parent tag and attributes. The advantage is we can give multiple attributes like: ID, Name, Value etc. to identify the elements.
Selenium.click (“//tagname [@ attributes]”);
Selenium.click (“//input [@value= ’clear’]”);
Selenium.click (“//input [@value= ‘clear’ and @class = ‘log’]”);
If you are unable to identify the element by using the Relative X-Path, then we can go for Absolute X-Path.
- It will identify the element with the hierarchical tags of the field.
- We can take the Absolute X-Path & Relative X-Path from the use of Fire Path and Firebug tool
- Firebug and Fire Path are compatible with only Firefox browser.