Skip to content
Selenium WebDriver · error message

Selenium: MoveTargetOutOfBoundsException: move target out of bounds

Permanent - do not retryClicking & interacting

Last verified

The exact message
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds

What it means

An Actions API command (ActionChains in Python, Actions in Java) tried to move the mouse pointer to a point outside the browser's viewport. WebDriver's pointer actions work in viewport coordinates and do not scroll automatically for offsets, so if the target point is off-screen, the move is rejected.

It most often follows move_to_element or move_to_element_with_offset on an element below the fold, or offsets calculated for a larger screen. Since Selenium 4, offsets for move_to_element_with_offset are measured from the element's center, not its top-left corner, so code written for Selenium 3 can now aim outside the element and the viewport. Small headless window sizes (800x600 by default in some setups) make it more likely.

What is not wrong: the element exists and was found; the pointer target is simply unreachable from the current scroll position.

What it looks like

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

slider = driver.find_element(By.CSS_SELECTOR, "#price-slider .handle")
ActionChains(driver)\
    .scroll_to_element(slider)\
    .click_and_hold(slider)\
    .move_by_offset(60, 0)\
    .release()\
    .perform()

Why it happens

  • The element is below or beside the visible viewport and was not scrolled into view first.
  • Offsets assume the top-left origin used in Selenium 3, while Selenium 4 measures from the element's center.
  • The headless window is smaller than the layout the coordinates were written for.
  • move_by_offset accumulates past the viewport edge during drag or drawing actions.

How to fix it

  1. Scroll first: ActionChains(driver).scroll_to_element(el).perform(), then move to it.
  2. Recalculate offsets relative to the element's center for Selenium 4.
  3. Set an explicit window size, for example options.add_argument('--window-size=1920,1080').
  4. For drag and drop within visible areas, prefer drag_and_drop(source, target) over manual offsets.
  5. If you only need a click, use element.click(), which scrolls into view automatically.

How to stop it recurring

Use a fixed, realistic window size in every environment, scroll elements into view before pointer actions, and compute offsets from element dimensions rather than hard-coded pixels. Prefer element-level methods over raw coordinates wherever possible, and revisit offset math when upgrading from Selenium 3.

Official documentation: www.selenium.dev/documentation/webdriver/troubleshooting/errors/#movetargetoutofboundsexception. See all Selenium error messages.

Related errors

Definitions

Quick answers

What does "MoveTargetOutOfBoundsException: move target out of bounds" mean in Selenium?

An Actions API command ( ActionChains in Python, Actions in Java) tried to move the mouse pointer to a point outside the browser's viewport. WebDriver's pointer actions work in viewport coordinates and do not scroll automatically for offsets, so if the target point is off-screen, the move is rejected.

How do I fix "MoveTargetOutOfBoundsException: move target out of bounds"?

1. Scroll first: ActionChains(driver).scroll_to_element(el).perform(), then move to it. 2. Recalculate offsets relative to the element's center for Selenium 4. 3. Set an explicit window size, for example options.add_argument('--window-size=1920,1080'). 4. For drag and drop within visible areas, prefer drag_and_drop(source, target) over manual offsets. 5. If you only need a click, use element.click(), which scrolls into view automatically.

Run browser automation you can watch and take over

Autonoly runs each job in a real cloud Chromium browser driven by Playwright. Timeouts and detached elements still happen; the difference is that you can watch the run live, see the step that failed, and take control of the browser to finish it.

Also see Live browser control.