TestProject Forum
Powered by leading experts in the test automation community

Element is present in DOM but test case is failing

I recorded a test where I am trying to create a new item and save it and then trying to verify that the item is present on that page. I used a random generator to generate the name of the item. The random name is generated successfully but after it has been generated, I want to validate that the name generated is present on that page.
Here is what my test looks like:

When I run this test, it fails at the last step with this message:
Message

Action failed using following locators:

  1. XPATH=//strong[. = ’ Mildrid Bagnold ']
    Element is present

When I download the DOM of the failed test and search for this name, it is displayed on that DOM. I also tried doing the same test with an existing item on the page and it works fine and it has the same XPATH for that item, it is only having trouble when I am creating the item with a random generator. Can you please suggest some solution for it?

Hello @rsood
First the message ‘Element is present’ should not be there if the element is not present so we will check that.
Regarding the failure, can you please go to the Locator tab in the recorder, put the locator you are using with the random name generated there, and see if it finds the element you created.

Thanks for the suggestion @ran.tzur. So as per your suggestion, I put a validation to check if the element is invisible and then my test passed. So, do I need to wait for the element to be visible? I tried using the Wait in the recorder but that’s not helping. Do you have any suggestions for this?
I also tried putting the locator in the locator tab in the recorder, but still no luck, it’s giving me the same message as before.

Also, I noticed that in the documentation part of TestProject which is in this link: https://docs.testproject.io/getting-started/available-validations
the definition for the validation, Is invisible? is: Checks if an element is invisible or not present in the Screen/ DOM.
But if I look at the test case and do a validation for Is Invisible? the definition over there is Checks if an element is invisible or not present on the screen but is still in DOM.
Just wanted to clarify that when I put this validation, is the element present in the DOM or not?

Thank you so much for all your help. I am trying to learn the tool.

Thanks,
Ritika

Hello @rsood
The Is invisible? action doesn’t check if the element is present or not in the DOM, only if its invisible.
So we will change the Docs.

Regarding the original issue, if the locator was not found in the Locator tab means the locator is not correct.

You can check other locators, see if there aren’t any extra spaces.
You can also try //strong[contains(text(), ‘Random generated name here’)]