Can WebDriver perform click and hold actions in headless Chrome mode?

I’m working on a web automation project and running into some issues with mouse interactions. When I try to implement drag and drop functionality using WebDriver’s action chains in a headless Chrome browser, the click and hold operations don’t seem to respond properly.

The strange thing is that when I run the exact same automation script with a regular Chrome browser (with GUI), everything works perfectly fine. The drag operations execute without any problems.

Has anyone experienced similar behavior with headless browsers? Are there any known limitations with mouse events like clickAndHold when running in headless mode? I’m wondering if this is a common issue or if there’s something specific I need to configure differently for headless execution.

Any suggestions or workarounds would be really helpful.

Yeah, headless Chrome gets weird with mouse interactions. Add the --disable-web-security flag and use ActionChains with pause() between moves. The DOM sometimes doesn’t register clicks without visual feedback, so you might need to trigger JavaScript events manually instead of using Selenium’s click methods.

Had this exact issue six months ago on a scraping project. The problem isn’t WebDriver’s click-and-hold in headless mode - it’s websites detecting headless browsers and blocking mouse events differently. Here’s what fixed it for me: Set your user agent string manually and add --disable-blink-features=AutomationControlled to your Chrome options. This makes you look like a real browser. Also, add longer delays between action chain commands. Headless mode needs more time to register events properly. And double-check that your target elements are fully loaded in the DOM before dragging - headless browsers love executing actions before elements finish rendering, even with explicit waits.

I had the same issue with drag-and-drop automation. Headless Chrome doesn’t calculate element positions properly without a visible viewport. Here’s what fixed it for me: Add --window-size=1920,1080 to your Chrome options and scroll elements into view before any actions. Don’t use clickAndHold directly - do move_to_element first, then click_and_hold separately. Also, headless mode needs small delays between moves since timing matters more. This combo worked consistently across different headless setups.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.