Wait for iframe to load - same element on different screens

Hi, I am kinda new to automation testing and I am just a self-learner. I have done a script and it works but I would like to optimize it. I searched the forum but wasn’t able to find related issues.

I am testing an app with iframe. The workflow can be like this - DefaultContent: click on button → SwitchToFrame: fill some inputs - click on Next → click on Next (only confirmation of the data is on this page) → (if element is displayed click Back)-(else click Next) → fill some more data and click Next. (Just an example - more things can happen).

There is a big delay between loading new data to the iframe. Whenever I click next button - it might take up to 30 secs to load the new elements. I found a way with WebUI.delay but it is not ideal.

The issue is that when I click next - the iframe still shows old data - this means that Katalon will look for expected new data on the old page. The time that it takes to load new data is not stable so sometimes it’s 30 sec and sometimes only 10 sec - so it is not optimal to delay by full 30 sec.

I can’t do WaitForElementPresent either because sometimes all I want to do on the next page is to click next. (On the pages there is no difference between the buttons - all Next buttons have the same html configuration) - so when I click(Next) → WaitForElement(Next) - Katalon finds the old Next button and is unable to click on the new one.

I tried WaitForPageLoad when switched on the iframe and even in default content but it says the page is loaded (even though new data has not been yet displayed).

I got an idea that I could wait until the pressed Next button dissapear and then check for the new elements but WaitForElementNotPresent doesn’t do the trick for me (I don’t really know why) - I set the timeout to 30 and it waits full 30 seconds again even though the button dissapeared after 20 sec.

Could someone please help with this issue? Any idea or tips will be really appreciated!

Hi Ondrej

The issue is that when I click next - the iframe still shows old data -
this means that Katalon will look for expected new data on the old page.
The time that it takes to load new data is not stable so sometimes it’s
30 sec and sometimes only 10 sec - so it is not optimal to delay by
full 30 sec.

You might be new at this but I think you have done a great job of focusing on the key part of the problem, and you explained it very clearly. Full marks! B)

Do you know if the URL itself changes in ANY way? Are there perhaps any post or search parameters present - and do they change? For example https://www.example.com/?param=value or https://www.example.com/#something

The reason I ask is that I have a similar situation. My solution was to first get the current URL, then perform the click on the next button, then wait until the URL has changed which proves the old page has unloaded. In short, I wrote my own waitForPageUnload API.

Come back with an answer and we’ll see if we can move you forward…