Skip to content
CodeKruPro

Wait for two elements that appear at different times

Automation taskMediumAsked in: Infosys

Interviewers ask: "How do you handle AJAX content that loads after the page?" AJAX means the page fetches data in the background. Give each element its own explicit wait for its own condition, so the test moves on as soon as the page allows.

Wait for Elements Appearing at Different Times

Wait for Element to Appear

Combine multiple waits to handle elements that appear at different times.

On the Appearing Elements page:

  • appearing5sec appears after 5 seconds
  • appearing10sec appears after 10 seconds

Task:

  1. Navigate to https://testkru.com/Interactions/AppearingElements
  2. Wait for appearing5sec to become visible, print its text
  3. Wait for appearing10sec to become visible, print its text

Expected output:

First: Message appeared after 5 seconds
Second: Message appeared after 10 seconds