Locators in Selenium RC and Webdriver

We have Locators in Selenium RC and Webdriver to identify the web elements. Some useful locators are mentioned below:

ID

Name

Link text

CSS

X-path

 

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:

Locators in Selenium RC and Webdriver


Locators in Selenium RC and Webdriver

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:

  1. Relative X-Path
  2. Absolute X-Path 

Relative 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.

Syntax:

Selenium.click (“//tagname [@ attributes]”);

Selenium.click (“//input [@value= ’clear’]”);

Selenium.click (“//input [@value= ‘clear’ and @class = ‘log’]”);

 

Absolute X-Path:

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.

 

Please click here to read Selenium RC Programmes

Please click here to read Selenium RC Specification

Please click here to read Steps for creating a project in Eclipse

Please click here to read Selenium Configuration with Java

Please click here to read Selenium Components

Please click here to read Selenium IDE

Please click here to read Advantages and limitations of Selenium IDE

Leave a Comment