Skip to content
CodeKruPro

Wait until an element is visible

Automation taskMediumAsked in: Accenture, BrowserStack, Capgemini, Cognizant, Infosys, TCS, Wipro

Interviewers ask: "A message appears a few seconds after the page loads. How do you read it reliably?" The answer is an explicit wait for visibility (a wait for one condition, set up in your test code), never a fixed sleep. The wait checks the page again and again and returns as soon as the message shows.

Explicit Wait - Element Visible

Explicit Wait - visibilityOfElementLocated

An explicit wait waits for a specific condition before proceeding. Use WebDriverWait with ExpectedConditions.

On the Appearing Elements page, the element with ID appearing5sec becomes visible after 5 seconds.

Task:

  1. Navigate to https://testkru.com/Interactions/AppearingElements
  2. Use WebDriverWait to wait for appearing5sec to become visible (max 10 seconds)
  3. Print its text once visible

Expected output:

Element visible: Message appeared after 5 seconds