Understanding Selenium Timeouts
Related Product On This Page What are Selenium Timeouts?June 22, 2026 · 14 min read · Tool Comparison
Timeouts in Selenium help manage wait times for elements or page loads, ensuring tests don’t fail abruptly. Optimizing timeouts improves user experience by handling delays gracefully and avoiding premature test failures. Types of Selenium Timeout Timeout with Wait: Timeout without Wait: Common Causes of TimeoutException This article explains how testers can configure different types of timeouts in Selenium to handle delays effectively before triggering exceptions. Selenium Timeouts are the longest periods of time for which a WebDriver should wait for specific actions or events to occur during a webpage interaction before it throws any error. Consider a situation in which WebDriver fails to execute the test case as the webpage takes too long to load. In such cases, it is essential to mention the wait time for the page load to avoid test case failure. This is where Timeouts play an essential role. They are used to set an interval between actions performed on the test. Timeouts are usually performed using . The various Selenium Webdriver timeouts used while testing an application are as follows: This article will explain how testers can set these timeouts with examples in Java and Python. Also Read: While often used interchangeably in casual conversation, “wait” and “timeout” have distinct meanings in the context of Selenium: Wait A wait mechanism is a conditional pause in the script execution. It is designed to wait for a specific condition to be met (for example, an element to be visible, clickable, or a certain text to appear) before proceeding with the next step. Selenium offers both implicit and explicit waits to handle the dynamic loading of web elements. Timeout A timeout is the maximum duration for which a wait mechanism (either implicit or explicit) will attempt to satisfy the specified condition. If the condition is not met within this defined timeframe, a TimeoutException is raised, halting the script execution. Timeouts act as a safeguard to prevent the script from waiting indefinitely. In essence, a wait is the action of pausing and checking for a condition, while a timeout limits how long that action will be performed. Read More: Here are the types of Selenium Timeouts: These timeouts are associated with the wait mechanisms in Selenium, defining the maximum duration to wait for a specific condition. 1. implicitlyWait() Implicit Wait directs the Selenium WebDriver to wait for a certain measure of time before throwing an exception. Once this time is set, WebDriver will wait for the element before the exception occurs. Once the command is run, Implicit Wait remains for the entire duration for which the browser is open. It’s default setting is 0, and the specific wait time needs to be set by the following protocol. implicitlyWait() timeout is used to specify the time the driver should wait while searching for an element if it is not immediately present. The syntax is as follows: When searching for a particular single element, the driver should pause page loading until the element has been found. If it doesn’t wait, the timeout expires before throwing a NoSuchElementException. Read More: When searching for multiple elements, the driver should pause the page until at least one element has been found or the timeout has expired. Example: In this statement, the WebDriver will wait for 20 seconds before proceeding to the next action. Code Snippet: On executing the code above, the driver will wait for 20 seconds on the particular website even if the web element is not found. Note: If a user wants to increase the implicit wait timeout, it should be done carefully, as this will affect the test run time. Read More: 2. Explicit Wait (via WebDriverWait) allows the configuration of a timeout for a specific condition to be met before proceeding with the next step in the script. It uses the WebDriverWait class in conjunction with ExpectedCondition to define the condition to wait for. This provides more granular control over the waiting process compared to implicit wait. Code: Note: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. On Windows: “C:\\Path\\to\\ chromedriver.exe” On macOS/Linux: “/path/to/ chromedriver” Explanation: When the code is executed, Finally, the browser is closed automatically using driver.quit(). Read More: 3. Fluent Wait is an extension of explicit wait that allows the configuration of the polling frequency (how often to check for the condition) and ignoring specific types of exceptions while waiting for a condition. This offers maximum flexibility in defining the waiting strategy. Code: Highlights: Timeout: 20 seconds max Polling frequency: every 2 seconds Exception ignored: Explanation When the code is executed, These timeouts are not directly associated with waiting for specific conditions related to element presence or interactability. 1. setScriptTimeout() setScriptTimeout is a Selenium Timeout that specifies the time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, not null, or greater than 2e16 – 1, an error code with invalid argument will be returned. Syntax: The default timeout for setScriptTimeout method is zero. If you do not set time, then there are chances that executeAsyncScript method may fail because the JavaScript code may take more than the time allotted. To avoid such failures, set the setScriptTimeout. This is mainly used for Javascript objects and executors. Example: In the example above, if the time is not used, then there will be an error stating: “Timed out waiting for async script result”. To avoid this error, one should use setScriptTimeout. Read More: 2. pageLoadTimeout in Selenium PageLoadTimeout is a Selenium feature that specifies the maximum time that the WebDriver should wait for the page to render completely before throwing an exception. When the user navigates to a new page or reloads the current page, WebDriver waits for the web page to load completely. If it fails to load within the specified timeout duration, it throws a Timeout exception. This sets the time to wait for a page to load completely before throwing an error. If the timeout is negative, page loads can be indefinite. Syntax: This timeout is applicable only to driver.manage() and driver.navigate.to() methods. Example: In the code above, if your page does not load within 30 seconds, will be thrown. Selenium Timeouts must be included to create effective, comprehensive and seamlessly running test cases. This article intends to help in this regard by briefly explaining how Timeouts work, and how they can be incorporated into Selenium test scripts. To know more about Automation, refer to this piece on . Read More: The default timeout depends on the type of wait command used. TimeOut Exception in Selenium mainly occurs when a given condition is not met in the specified time. Timeout exception generally occurs when a Webdriver wait has finished waiting for a particular element to be present or any condition to be satisfied. To understand this, see an example where You will try to search for an element for a few seconds using webdriver wait. For the sake of understanding, the ID for the username given in the above example is incorrect. The driver cannot find the element between 10 seconds, and it throws a timeout exception as demonstrated below. This clearly shows that the driver tried to find the element’s visibility for 10 seconds, and as it could not find the element it threw a timeout exception. Now try to see the same example with the correct id for the username field, and you shall know the test has passed without throwing a timeout exception. Now you can see the same test has passed as the driver was able to find the element within the given time. Now see the same timeout example in Python. In this example, you have used the presence_of_element_located() function to find the element within the given time. Here too, you have deliberately given an invalid ID for the username field so that the driver is unable to find the element and throws a timeout exception as below. If you give the correct ID for the username element, the driver can find the element of the specified time, and the test passes as below. Several factors can lead to TimeoutException in Selenium: To effectively manage timeouts in Selenium and create robust test scripts, consider the following best practices: Read More: Here’s why you should use BrowserStack Automate for running Selenium tests: Handling timeouts effectively is crucial for building reliable and efficient Selenium tests. By understanding the types of timeouts and addressing common causes, testers can minimize failures, improve test stability, and ensure faster feedback cycles. You can run your Selenium tests across real browsers and devices with , helping you catch timeout issues early and deliver a smoother user experience. On This Page #Ask-and-Contribute about this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
Understanding Selenium Timeouts
Overview
What are Selenium Timeouts?
Difference between Wait and Timeout in Selenium
Types of Selenium Timeout
Timeout with Wait
implicitlyWait(long time, java.util.concurrent.TimeUnit unit);
implicitlyWait(20, TimeUnit.SECONDS);
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class TimeoutExample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "Path of Chrome Driver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.ebay.com/");
// Implicit wait timeout for 20seconds
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@id='gh-ac']")).sendKeys("Mobile");
//xpath for search button
WebElement search = driver.findElement(By.xpath("//input[@id='gh-btn']"));
search.click();
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class ExplicitWaitExample {
public static void main(String[] args) {
// Set the path of the ChromeDriver
System.setProperty("webdriver.chrome.driver", "C:\\Path\\To\\chromedriver.exe");
WebDriver driver = new ChromeDriver(); // Initialize WebDriver
driver.get("https://www.ebay.com/"); // Navigate to eBay
// Create an explicit wait instance with 20 seconds timeout
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
// Wait until the search input field is visible and enter the search term
WebElement searchInput = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id ("gh-ac")));
searchInput.sendKeys("Mobile");
// Wait until the search button is clickable and click it
WebElement searchButton = wait.until(ExpectedConditions.elementToBeClickable(By.id("gh-btn")));
searchButton.click();
driver.quit(); // Close the browser
}
}import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import java.time.Duration;
import java.util.function.Function;
public class FluentWaitExample {
public static void main(String[] args) {
// Set the path of the ChromeDriver
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
WebDriver driver = new ChromeDriver(); // Initialize WebDriver
driver.get("https://www.ebay.com/"); // Navigate to eBay
// Create a FluentWait with a maximum wait time of 20 seconds and a polling interval of 2 seconds
FluentWait<WebDriver> wait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(20))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(Exception.class);
// Wait for the search input field to be visible and then enter the search term
WebElement searchInput = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("gh-ac"));
}
});
searchInput.sendKeys("Mobile");
// Wait for the search button to be clickable and then click it
WebElement searchButton = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("gh-btn"));
}
});
searchButton.click();
driver.quit(); // close the browser
}
}Timeout without Wait
setScriptTimeout(long time,java.util.concurrent.TimeUnit unit);
// setScriptTimeout for 10 seconds
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
((JavascriptExecutor) driver).executeScript("alert('hello world');");
((JavascriptExecutor) driver).executeAsyncScript("window.setTimeout(arguments[arguments.length - 1], 500);");pageLoadTimeout(long time,java.util.concurrent.TimeUnit unit);
public class PageLoadTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "Path of driver");
WebDriver driver = new ChromeDriver();
// set the time of 30 seconds for page to complete the loading
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
}
}Default Timeout in Selenium WebDriver
How to handle a Timeout Exception in Selenium?
Wait wait = new FluentWait(driver)
.withTimeout(timeout, SECONDS)
.pollingEvery(timeout, SECONDS)
.ignoring(Exception.class);
Timeout Exception in Selenium Java
package com.qa.bs;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class timeOutExample {
@Test
public void timeOutTest()
{
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://app.hubspot.com/login");
//This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username1")));
}
}package com.qa.bs;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class timeOutExample {
@Test
public void timeOutTest()
{
System.setProperty("webdriver.chrome.driver","c:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://app.hubspot.com/login");
//This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds
WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
}
}Timeout Exception in Selenium Python
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome('C:/chromedriver.exe')
driver.get("https://app.hubspot.com/login")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username1')))from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Chrome('C:/chromedriver.exe')
driver.get("https://app.hubspot.com/login")
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username')))Common Causes of TimeoutException
Best Practices when using Selenium Timeout
Why use BrowserStack Automate for Selenium Tests?
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously