While automating a page, there should be some mechanism to locate the Web Elements with which the test interacts. Testsigma uses it's UI Identifiers to locate these Web Elements. UI Identifier of a Web Element for example, a button can be the value of its attributes. The common attributes for HTML Elements are id, title, name, type, placeholder, class, text e.t.c
When locating a Web Element using any of these attributes, we need to make sure that the value is unique. For example, if there are two buttons with the name 'submit' on the same page, we cannot use that attribute. In short, we need to get properties of an Element that is unique to it for usage as a UI Identifier. In cases where no other unique Identifiers are present, we will make use of Xpath locators or CSS locators.
However, there can be a number of issues when using UI Identifiers for your Test Steps. Some of them are:
- Problem 1 - Duplicate UI Identifiers
- Problem 2 - Hidden or disabled Elements
- Problem 3 - Incorrect/Invalid UI Identifiers
- Problem 4 - Empty UI Identifiers
- Problem 5 - Element not clickable
- Problem 6 - Stale Element
Problem 1 - Duplicate UI Identifiers
In this case, the Test Step might not actually fail. The Test Step will pass and the execution will continue although the correct Element was not selected. This is undesirable.
As you can see above, we used the xpath //input[@type='password'] and there are two matching Elements as shown in the image for the same xpath. This is a case of duplicate UI Identifiers and even if we need to select the second field, the first Element with the corresponding UI Identifiers will be selected always.
Use a different XPath that is unique for the element.
Problem 2 - Hidden or disabled Elements
Element is either hidden or disabled exception : If you found this error in your test step failure message, check whether;
- the given UI Identifier locates an Element that is actually present in the Web page. Sometimes, the element might be created dynamically and might not be present in the Web page during the Test Execution. In such cases, wait for the element to be present by adding a wait step.
- the given UI Identifier is hidden or disabled. Elements are sometimes hidden or disabled by the developer if they are not meant to be interacted with.
You can see the type='hidden' for this element. An element may be hidden also using class names such as 'hide', 'hidden' or directives such as 'ng-hide'
Problem 3 - Incorrect/Invalid UI Identifiers
The element corresponding to the locator type "id_value" and locator "//*[@id='lgnjs']" is not displayed:
If you found a similar error in your test step failure message, check the selected locator type corresponds to locator value.
In the above message, locator type is 'id' but the given locator value is in 'xpath' format. Correct it and try again.
The element corresponding to the locator type "xpath" and locator "//button[@type='value']" is not displayed:
We can rule out the mismatch of Locator Type and Locator value in the above message.
If you found this error message in your test step failure message, check the UI Identifier manually to confirm that
- the element is actually displayed in the present page.
- the element is not contained in an Iframe or other external Frames. If yes, please add a Step to switch to that frame.
- the UI Identifier value is correct or not.
Problem 4 - Empty UI Identifiers
The element corresponding to the locator type "id_value" and locator "" is not displayed:
If you found this error message in your test step failure message, check the value of the UI Identifier and make sure that ui identifier value is not be empty.
Problem 5 - Element not clickable
Element not clickable at point (x,y). Other element would receive the click:
If you face the above error,
- check whether the Element is actually visible in the Test Step Screenshot(inside the Browser view port). If the Element is not inside the view, add a Test Step to scroll to the Element.
- check whether the Element is overlapped by any other Element(like sticky menus, drop down menus or alerts).
- If the Element is covered or overlapped by another element temporarily(during a page load), add a wait step for the overlapping element to be removed
- If the Element is covered or overlapped by another element, add a Step to close/remove the overlapping Element.
Problem - 6 - Stale Element Exception
The element corresponding to the locator type "X" and locator "Y" cannot be interacted with since it is no longer appears/exists on the DOM of the page
Cause: The element you are trying to interact with might be a dynamically rendered element that detaches/reattaches itself to the DOM/ HTML Source dynamically after the page load is complete
This Error is caused due to 2 reasons:
- The element has been deleted entirely.
- The element is no longer attached to the DOM.
The second case is the most common cause. Page Elements are detached from the DOM during AJAX requests or Page reloads and reattach automatically once the function is executed.
If you face the above error,
- Add a wait step so as to allow time for the element to be added to the DOM using the "Wait for test data seconds" template as shown here: How to add a Wait in Test Cases?
- Add a Page Refresh step so that the element is loaded quickly on next reload.