<!--
{
  "availability" : [
    "Xcode: 16.3.0 -",
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCUIAutomation",
  "identifier" : "/documentation/XCUIAutomation/XCUIElement/click(forDuration:thenDragTo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCUIAutomation"
    ],
    "preciseIdentifier" : "c:objc(cs)XCUIElement(im)clickForDuration:thenDragToElement:"
  },
  "title" : "click(forDuration:thenDragTo:)"
}
-->

# click(forDuration:thenDragTo:)

Clicks and holds an element for a duration you specify, and then drags it to another element.

```
func click(forDuration duration: TimeInterval, thenDragTo otherElement: XCUIElement)
```

## Parameters

`duration`

The duration of the initial click and hold.

`otherElement`

The element over which to finish the drag.

## Discussion

Specify a duration long enough to initiate a drag operation. If the element exists within a scrollable view but is offscreen, the framework attempts to scroll the element onscreen before performing the click.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)