Skip to content
CodeKruPro

Wait until an element disappears

Automation taskMediumAsked in: Infosys

"How do you wait for a loading spinner to go away before you click?" Wait for the spinner to become invisible, then act. The same pattern works for short messages (toasts) that appear and fade out. Here you check that an element is visible at first, wait for it to disappear (it takes 5 seconds) and print the result.

Wait for an Element to Disappear

Wait for Element to Disappear

invisibilityOfElementLocated waits until an element is no longer visible. This is useful for waiting for loading spinners or messages to disappear.

On the Disappearing Elements page, disappearing5sec disappears after 5 seconds.

Task:

  1. Navigate to https://testkru.com/Interactions/DisappearingElements
  2. Verify disappearing5sec is initially visible
  3. Wait for it to become invisible (max 10 seconds)
  4. Print whether it disappeared

Expected output:

Initially visible: true
Disappeared: true