Skip to content
CodeKruPro

Click and hold an element, then release

Automation taskMediumAsked in: Accenture, Capgemini, Infosys, TCS, Wipro

"How do you test a long press, or a drag done step by step?" Click and hold, read the state while the button is down, then release. These are the building blocks of a manual drag.

Click and Hold Action

Click and Hold

clickAndHold() presses the mouse button without releasing. Combined with moveToElement() and release(), it allows manual drag operations.

On the Drag and Drop page, holding a box for 1 second changes its text (e.g., "Holding Box 1").

Task:

  1. Navigate to https://testkru.com/Interactions/DragAndDrop
  2. Find Box 2 (id="box2")
  3. Use clickAndHold, wait 1.5 seconds, then release
  4. Print the box text during hold (it changes to "Holding Box 2")

Expected output:

During hold: Holding Box 2