Selenium IDE- Locating Strategies (By Identifier)
- Identifier was used as a default type earlier and not recommended now as it’s not supported by WebDriver.
- With identifier, we can use locating strategies like ID and Name both.
- The first element with the matching ID attribute is used.
- If no element has a matching ID attribute then the first element with a matching name attribute is used.
- For example, Identifier=login (this could be ID or Name).
Let us consider an example on how to use Identifier locator as a target for commands in Selenium IDE.
We will create a login test, so that you could get a better understanding of locating elements through Identifier.
- Launch Firefox browser.
- Click on the Selenium icon present on the top right corner on your browser.
- It will launch the default interface of Selenium IDE.
- Click on the command text box present on the Test Script Editor Box.
- Modify the properties of first command as:
- Command: open
- Target:https://mail.rediff.com/cgi-bin/login.cgi
- After execution, this command will load the Rediff login page on your Firefox browser.
For second command to be entered, we need a unique identification element for the Username text box which will help the IDE to identify the target location.
-
- Right click on the “Username” text box and select Inspect Element.
-
- It will launch a window containing all the specific codes involved in the development of the “Username” text box.
-
- Pick the first element with the matching ID attribute that contains the specific ID for the “Username” text box.
- Modify the properties of second command as:
- Command: click at
- Target: identifier=login1
- After execution, this command will click on the Username text box.
We will use the same identifier element for our next command.
- Modify the properties of third command as:
- Command: type
- Target: identifier=login1
- Value: username
- After execution, this command will type the username in the Username text box.
We will now add a command that will click on the “Password” text box. For this command, we need a unique identification for the “Password” field which will help the IDE to identify the target location.
-
- Right click on the “Password” text box and select Inspect Element.
-
- It will launch a window containing all the specific codes involved in the development of the “Password” text box.
-
- Pick the first element with the matching ID attribute that contains the specific ID for the “Password” text box.
- Modify the properties of fourth command as:
- Command : click at
- Target : identifier=password
- After execution, this command will click on the Password text box.
We will use the same ID element for our next command which involves typing the password as login credential.
- Modify the properties of fifth command as:
- Command : type
- Target : identifier=password
- Value : **********(User Login Password)
- Upon execution this command will type the user password as the login credential.
At last, we need a unique identification element for the Login Submit button which will help the IDE to identify the target location.
-
- Right click on the “Go” button and select Inspect Element.
-
- It will launch a window containing all the specific codes involved in the development of the “Go” submit button.
-
- Pick the first element with the matching name attribute that contains the specific name for the “Go” submit button.
- Modify the properties of sixth command as:
- Command : click at
- Target : identifier=proceed
- After execution, this command will click on the “Go” submit button.
- Click on the “Run Current Test” button present on the tool bar menu of the IDE. It will execute all of your inserted commands on the browser and gives you an overall summary of the executed test script.
- The Log pane displays the overall summary of the executed test scripts.
Thus, you can see that we have used identifier locator as a target for most of our Selenium commands.