October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Drag and Drop Elements with Selenium and Python

Learn the Selenium Python ActionChains calls for element-to-element and offset-based drag and drop, plus ways to verify and troubleshoot the result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium Python’s ActionChains: locate the source and destination elements, call drag_and_drop(source, target), then execute the queued actions with .perform(). For a destination defined by a relative position rather than an element, use drag_and_drop_by_offset().

Drag an element onto a target element

With a configured WebDriver session and locators that match the page, the basic pattern is:

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

source = driver.find_element(By.ID, "source")
target = driver.find_element(By.ID, "target")

ActionChains(driver).drag_and_drop(source, target).perform()

Replace the example IDs with stable locators from your page. Selenium documents this gesture as holding the left mouse button on the source, moving to the target, and releasing. Selenium Python ActionChains API

What the call does

ActionChains queues input actions. The call to perform() sends them to the browser in order; constructing the chain without performing it does not execute the drag. The API documentation describes drag_and_drop(source, target) as a left-button drag between two WebElements. Selenium Actions API

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Drag by a relative offset

When the endpoint is best described as a displacement from the source, use integer X and Y offsets instead of locating a target element:

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

source = driver.find_element(By.ID, "source")

ActionChains(driver).drag_and_drop_by_offset(source, 120, 40).perform()

The offsets are the intended horizontal and vertical displacement. Choose values for the page layout and the drop area you need; this method does not identify a semantic destination element for you. Selenium Python ActionChains API

Verify the application accepted the drag

A completed Selenium input sequence proves that the browser received the actions, not that the page’s application logic accepted the drop. After the drag, assert an outcome that matters to the test, such as the item’s new parent, its updated position in a list, or a confirmation message. The expected result and the right wait condition depend on the page under test; Selenium’s general Actions documentation does not define a universal success signal for custom drag handlers.

Timing and interaction details

The current Python API documentation identifies Selenium version 4.50.0 and specifies a default pointer movement duration of 250 milliseconds for ActionChains; the duration can be overridden when constructing the chain. That value is an API default, not a guarantee that a particular page’s drag implementation will respond successfully. Selenium Python ActionChains API

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot a drag that does not work

  • Nothing happens: Confirm that the source and destination locators identify the intended elements and that the chain ends with .perform().
  • The chain runs but the page is unchanged: Check the page state with an application-level assertion. A dispatched mouse gesture is not proof that a custom handler accepted it.
  • The drop lands in the wrong place: Prefer drag_and_drop(source, target) when a destination element can be located. If using offsets, reassess the intended displacement and target region.
  • A custom drag interaction still fails: Investigate how that page implements dragging and what region accepts the drop. The general Selenium documentation does not establish a browser-by-browser compatibility matrix or a universally reliable workaround for custom JavaScript or HTML5 drag behavior. Do not assume that injecting JavaScript events will fix it.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot of the page rather than an automated drag interaction, ScreenshotNeo returns a screenshot or PDF from one API request. For example, this cURL request saves a WebP screenshot of a page:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for setup and options. ScreenshotNeo removes cookie banners, popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.