Skip to main content
← TesterRank/Automation Cheatsheet
Cheatsheets

Common Errors Cheatsheet

12 most common Selenium errors — what they mean, why they happen, and how to fix them.

Showing 12 of 12 errors

1NoSuchElementException

What it means

The element you are trying to find does not exist in the current DOM.

Common causes

  1. Wrong locator (typo in ID, incorrect XPath)
  2. Element has not loaded yet (page still loading)
  3. Element is inside an iframe (need to switch to frame first)

How to fix

Verify your locator in browser DevTools first. Add an explicit wait before finding the element. Check if the element is inside an iframe.

Example

// Wrong — no wait, element may not be loaded
driver.findElement(By.id("loginBtn")).click();

// Correct — wait for element first
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn"))).click();
2StaleElementReferenceException

What it means

You found an element, but by the time you interact with it, the DOM has changed and the reference is outdated.

Common causes

  1. Page refreshed or navigated after finding the element
  2. AJAX call updated the DOM (element was re-rendered)
  3. Single Page App re-rendered the component

How to fix

Re-find the element after any DOM change. Use explicit waits. In React/Next.js apps, this is common after state updates.

Example

// Wrong — element reference becomes stale after page refresh
WebElement btn = driver.findElement(By.id("submitBtn"));
driver.navigate().refresh();
btn.click(); // StaleElementReferenceException!

// Correct — re-find after DOM change
driver.navigate().refresh();
wait.until(ExpectedConditions.elementToBeClickable(By.id("submitBtn"))).click();
3TimeoutException

What it means

Your explicit wait condition was never met within the timeout period.

Common causes

  1. Element never appeared on the page
  2. Wrong ExpectedCondition (e.g., waiting for clickable but element is disabled)
  3. Timeout too short for the operation

How to fix

Check if the element actually appears on the page. Verify the ExpectedCondition matches what you need. Increase timeout if the page is genuinely slow.

Example

// Check what condition you actually need
// If element exists but is hidden:
wait.until(ExpectedConditions.presenceOfElementLocated(...)); // not visibility

// If element is visible but disabled:
wait.until(ExpectedConditions.visibilityOfElementLocated(...)); // not clickable
4ElementNotInteractableException

What it means

Element exists and is found, but you cannot click or type in it right now.

Common causes

  1. Element is present in DOM but not visible on screen
  2. Element is behind an overlay, modal, or loading spinner
  3. Element is disabled or read-only

How to fix

Wait for the element to be visible and clickable. Scroll the element into view. Close any overlays first.

Example

// Scroll into view first
((JavascriptExecutor) driver).executeScript(
    "arguments[0].scrollIntoView(true)", element
);

// Then wait for clickable
wait.until(ExpectedConditions.elementToBeClickable(element)).click();
5ElementClickInterceptedException

What it means

Another element is covering the element you want to click.

Common causes

  1. Cookie consent banner covering the button
  2. Floating header/footer overlapping the element
  3. Modal or popup blocking the click

How to fix

Close the overlay first. Scroll to move the element clear of fixed headers. Use JavaScript click as a last resort.

Example

// Option 1: Close the overlay
driver.findElement(By.id("closeBanner")).click();

// Option 2: Scroll past fixed header
((JavascriptExecutor) driver).executeScript(
    "arguments[0].scrollIntoView({block: 'center'})", element
);

// Option 3: JavaScript click (bypasses overlay)
((JavascriptExecutor) driver).executeScript("arguments[0].click()", element);
6InvalidSelectorException

What it means

Your XPath or CSS selector syntax is wrong.

Common causes

  1. Typo in XPath expression (missing quotes, wrong brackets)
  2. Invalid CSS selector syntax
  3. Using XPath syntax in a CSS selector method or vice versa

How to fix

Test your selector in browser DevTools first: press F12, go to Console, type document.querySelector("your-css") or $x("your-xpath") to verify.

Example

// Wrong — unescaped quotes
driver.findElement(By.xpath("//button[text()="Login"]")); // Syntax error!

// Correct — use single quotes inside double quotes
driver.findElement(By.xpath("//button[text()='Login']"));

// Test in DevTools Console first:
// $x("//button[text()='Login']")  → for XPath
// document.querySelector("#loginBtn") → for CSS
7WebDriverException

What it means

Generic driver-level failure — the browser or driver crashed.

Common causes

  1. ChromeDriver version does not match Chrome browser version
  2. Browser crashed or was closed externally
  3. Driver executable not found in PATH

How to fix

Use WebDriverManager to auto-manage driver versions. Check browser is installed and not being updated during tests.

Example

// Use WebDriverManager to avoid version mismatch
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();

// Or in Selenium 4.6+ (built-in Selenium Manager):
WebDriver driver = new ChromeDriver(); // Auto-downloads driver
8SessionNotCreatedException

What it means

Cannot start a new browser session.

Common causes

  1. Chrome browser version incompatible with ChromeDriver version
  2. Browser not installed on the machine
  3. Another process using the same debug port

How to fix

Update ChromeDriver to match your Chrome version. Use WebDriverManager for automatic version management.

Example

// Check Chrome version: chrome://version
// Check ChromeDriver version: chromedriver --version
// They must match (e.g., Chrome 124 → ChromeDriver 124)

// Best fix — use WebDriverManager:
WebDriverManager.chromedriver().setup();
9NoAlertPresentException

What it means

You tried to switch to a JavaScript alert, but no alert is displayed.

Common causes

  1. Alert has not appeared yet (need to wait)
  2. Alert was already accepted/dismissed
  3. The dialog is a custom HTML modal, not a browser alert

How to fix

Wait for the alert to appear before interacting. Check if it is a real browser alert or a custom HTML modal (custom modals need regular locators, not switchTo().alert()).

Example

// Wait for alert first
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();

// If it's a custom modal (not a browser alert):
driver.findElement(By.id("confirmBtn")).click(); // Use regular locator
10MoveTargetOutOfBoundsException

What it means

The Actions class tried to move to a point outside the browser viewport.

Common causes

  1. Element is off-screen (scrolled out of view)
  2. Element has zero width or height
  3. Using wrong coordinates for moveByOffset()

How to fix

Scroll the element into view before performing Actions on it.

Example

// Scroll into view first
((JavascriptExecutor) driver).executeScript(
    "arguments[0].scrollIntoView({block: 'center'})", element
);

// Then perform the action
new Actions(driver).moveToElement(element).click().perform();
11JavascriptException

What it means

The JavaScript code you executed via JavascriptExecutor threw an error.

Common causes

  1. Syntax error in your JavaScript code string
  2. Trying to access a null/undefined variable in JS
  3. Element reference (arguments[0]) is null

How to fix

Test your JavaScript in the browser DevTools Console first. Make sure the element reference is valid.

Example

// Test JS in DevTools Console first:
// document.querySelector("#loginBtn").scrollIntoView()

// Wrong — element might be null
((JavascriptExecutor) driver).executeScript(
    "arguments[0].click()", null  // throws JavascriptException
);

// Correct — find element first, verify it exists
WebElement element = driver.findElement(By.id("loginBtn"));
((JavascriptExecutor) driver).executeScript("arguments[0].click()", element);
12UnhandledAlertException

What it means

An unexpected browser alert appeared while trying to perform another action.

Common causes

  1. Previous action triggered an alert you did not expect
  2. Server returned an error that showed as an alert
  3. Confirmation dialog appeared before navigation

How to fix

Handle the alert before continuing. Add a try-catch to dismiss unexpected alerts.

Example

// Handle unexpected alerts
try {
    driver.findElement(By.id("nextBtn")).click();
} catch (UnhandledAlertException e) {
    driver.switchTo().alert().accept(); // Dismiss the alert
    driver.findElement(By.id("nextBtn")).click(); // Retry
}