TestProject Forum

How to do a single Coded Step for a while Loop


On our platform, we are able to give out passwords. Now unfortunately, the passwords do not have a consistent period where they appear in the dom. It could take anywhere from 5 seconds to around 45. I wanted to create a while loop to check if the element exists or not, so that the browser can keep refreshing until it appears. Unfortunately I can’t just ‘repeat’ a ‘browser refresh’ step a certain amount of times because it could take awhile for the item to appear. Is there a way to just do a coded step? Or do I need to make a whole sdk project, which I am also unfamiliar with.

Please let me know. Thank you!

Hi @ajacobs,
You can use the actions execute javascript,
and in code put this :

while (document.querySelector("#site-content > div:nth-child(1)")==null) {
await new Promise(r => setTimeout(r, 5000));

this will reload the page every 5 seconds while the element is not found.

you can take the element JSPath by opening dev tools and using inspect on the element

then right-click the element and copy the jsPath and replace that in the code above