Skip to content
CodeKruPro

Diagnose a wait that times out

Automation taskMediumPython onlyAsked in: Accenture

Interviewers ask: "Your explicit wait times out. How do you find out why?" Catch the TimeoutException, read what the wait expected, and compare it with what the page really does. Then fix the wait, for example a longer timeout or a better condition, instead of adding a sleep. In this lesson a 2-second wait on an element that takes 15 seconds fails, and then a long enough wait reads its message.

Diagnose a Wait That Times Out

Diagnose a Wait That Times Out

A wait that is shorter than the element raises TimeoutException. Catch that exception, print its name, then wait long enough to read the same element.

Task:

  1. Use a 2 second wait on #appearing15sec
  2. Print Wait failed: TimeoutException
  3. Wait long enough to print the message
  4. Assert that the message mentions 15 seconds

Print the lines below exactly.

Expected output:

Wait failed: TimeoutException
Later: Message appeared after 15 seconds