1

When we give a wait of 15 seconds and the application response time is 20 seconds, selenium throws an errorr

Which is the exception that selenium throws?

3
  • Please, share your code here to get more details. Jan 4 at 16:26
  • 1
    Please share the error you see Jan 4 at 17:10
  • I just want to know this I did not get any error because this question asks to my friend in an interview. And tomorrow is my interview. Jan 4 at 17:27

2 Answers 2

1

Selenium Web Driver Wait types:

  • Implicit Wait
  • Explicit Wait
  • Fluent Wait

The Implicit Wait in Selenium is used to tell the web driver to wait for a certain amount of time before it throws a No Such Element Exception. The default setting is 0. Once we set the time, the web driver will wait for the element for that time before throwing an exception.

The Explicit Wait in Selenium is used to tell the Web Driver to wait for certain conditions (Expected Conditions) or maximum time exceeded before throwing ElementNotVisibleException exception. It is an intelligent kind of wait, but it can be applied only for specified elements (it gives better options than implicit wait as it waits for dynamically loaded Ajax elements).

The Fluent Wait in Selenium is used to define the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Users may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementException when searching for an element on the page.

Documentation:

1

In Selenium, when a wait time specified in the code is not enough for an element to load or an action to be performed, a "TimeoutException" is thrown.

This exception is typically thrown when using the "WebDriverWait" class in Selenium, which is used to wait for a specified condition to be met before proceeding with the next step. If the condition is not met within the specified time, the "TimeoutException" is thrown.

For example, if we have a wait time of 15 seconds and the application response time is 20 seconds, the following code would result in a "TimeoutException":

WebDriverWait wait = new WebDriverWait(driver, 15); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));

In this case, the "visibilityOfElementLocated" condition is not met within the 15 seconds specified and the exception is thrown.

It's important to note that there are different types of waits in Selenium, such as Implicit wait and Explicit wait. An implicit wait is set for the entire session and will wait for a specified amount of time for elements to appear on the page before throwing a "NoSuchElementException". An explicit wait, as shown in the example above, is used for specific elements and will only wait for the specified amount of time for that particular element.

In conclusion, the "TimeoutException" is thrown in Selenium when the wait time specified is not enough for an element to load or an action to be performed, and is typically encountered when using the "WebDriverWait" class with an explicit wait.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.