You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium3.9.1+ChromeDriver2.36拖拽失败:Draggable1拖至Drop Box求助

Troubleshooting Drag-and-Drop Failure with Selenium 3.9.1 & ChromeDriver 2.36

Hey there, let’s dig into why your drag-and-drop action on that Selenium Easy demo page is failing, and walk through actionable fixes to get it working.

Common Causes of the Failure

  • Severe Version Compatibility Issues
    Your combo of Selenium 3.9.1 (released back in 2018) and ChromeDriver 2.36 (only compatible with Chrome 63-65) is extremely outdated. Modern web pages like the Selenium Easy demo likely use updated JavaScript drag-and-drop libraries (e.g., jQuery UI or native HTML5 APIs) that old versions of Selenium/WebDriver don’t handle well. The Actions class in these older Selenium versions has known bugs with non-native JS-driven drag interactions.
  • Unreliable Element Locators
    If you’re using flimsy locators (like overly complex XPaths or dynamic class names) to target Draggable1 or the Drop Box, you might be interacting with the wrong element entirely—leading to failed drag attempts.
  • Missing Explicit Waits
    Trying to drag elements before the page fully loads or the elements become interactive is a common pitfall. Even if elements are visible, they might not be ready to accept drag events yet.
  • Limitations of Native Actions Class
    Older Selenium’s dragAndDrop() method often struggles with drag-and-drop components that are powered by custom JavaScript, rather than native HTML5 drag events.

Fixes to Try (Ordered by Effectiveness)

1. Upgrade Your Tooling (Most Critical Fix)

This is the single best way to resolve the issue long-term:

  • Upgrade Selenium to the latest stable 4.x release (it includes massive improvements to drag-and-drop handling and modern browser compatibility).
  • Match your ChromeDriver version to your installed Chrome browser (check Chrome’s version via chrome://settings/help, then download the corresponding ChromeDriver—just ensure version numbers align closely).

2. If You Can’t Upgrade: Use Reliable Locators & Explicit Waits

First, ensure you’re targeting elements with stable locators. For the demo page:

  • Draggable1 has a unique ID: draggable1
  • Drop Box has a unique ID: droppable

Pair these with explicit waits to ensure elements are interactive before dragging:

// Set up explicit wait (10-second timeout)
WebDriverWait wait = new WebDriverWait(driver, 10);

// Wait for elements to be ready for interaction
WebElement draggable = wait.until(ExpectedConditions.elementToBeClickable(By.id("draggable1")));
WebElement droppable = wait.until(ExpectedConditions.elementToBeClickable(By.id("droppable")));

3. Try Step-by-Step Actions Simulation

Instead of using the one-shot dragAndDrop() method, break the action into individual steps—this often works better with older Selenium versions:

Actions actions = new Actions(driver);
actions.clickAndHold(draggable)
       .moveToElement(droppable)
       .release(droppable)
       .build()
       .perform();

4. Simulate Drag-and-Drop via JavaScript

If native Selenium actions still fail, bypass them entirely by executing JavaScript to trigger the drag events (this works for most JS-powered drag components):

JavascriptExecutor js = (JavascriptExecutor) driver;

// JS script to simulate drag-start, drop, and drag-end events
String dragScript = "function dragDrop(source, target) {" +
    "var dragStart = new MouseEvent('dragstart', {bubbles: true, cancelable: true});" +
    "source.dispatchEvent(dragStart);" +
    "var drop = new MouseEvent('drop', {bubbles: true, cancelable: true});" +
    "target.dispatchEvent(drop);" +
    "var dragEnd = new MouseEvent('dragend', {bubbles: true, cancelable: true});" +
    "source.dispatchEvent(dragEnd);" +
"}";

// Execute the script with your target elements
js.executeScript(dragScript + "dragDrop(arguments[0], arguments[1]);", draggable, droppable);

Final Notes

The version upgrade is hands down the most sustainable fix—old Selenium/ChromeDriver combinations will only cause more compatibility headaches with modern web pages. If you go the workaround route, start with explicit waits and reliable locators before moving to JavaScript simulation.

内容的提问来源于stack exchange,提问作者Jomon Johny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:10:16