In this topic, we described about the below sections -
Identifier was used as a default type earlier and used locating strategies both ID and Name. This strategy first tries to find out first matching ID attribute element. If matching ID element is found, the element uses for testing. If the matching ID attribute element not found, then it tries to find first matching name attribute element. If found, the first matching name attribute element used for testing. Otherwise, test case execution gets failed.
- This strategy doesn’t depend on the page structure.
- Works even if the page structure changes
- Easily matches several elements.
- Only works on the first matched element.
Now, let’s understand the working of ID locator with the help of a simple example. For example, we will launch Firefox and navigate to google.com. Here, we try to locate the search box using identifier Locator.
From the above screen shot, the below code specifies locate identifier code –
While running the test, it first searches for the below identifier -
If "Id=q" found, the first found identifier uses for testing.
If "Id=q" not found, it again searches for the below identifier -
If "name=q" found, the first found identifier uses for testing. If "name=q" not found, then running test case gets failed.