At least as of Swift 4.1, Xcode 9.4.1, the values you need represent a percentage of the element's width and height - 0.0 to 1.0.
For a long swipe, you need to drag across the element about 60%, so like this:
// right long swipe - move your 'x' from 0.0 to 0.6
let startPoint = element.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0))
let endPoint = element.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.0))
startPoint.press(forDuration: 0, thenDragTo: endPoint)
and:
// left long swipe - move your 'x' from 0.6 to 0.0
let startPoint = element.coordinate(withNormalizedOffset: CGVector(dx: 0.6, dy: 0.0))
let endPoint = element.coordinate(withNormalizedOffset: CGVector(dx: 0.0, dy: 0.0))
startPoint.press(forDuration: 0, thenDragTo: endPoint)
You could set your dy
value to 0.5, say, if you're wanting to drag at the center of the element. But, note that your dy
values must be the same for swiping right or left. If you were to convert this for a swipe up or down, the dx
values would need to be identical, while the dy
values would change appropriately instead. (The swipe needs to move along a straight line.)
Note, also, that the forDuration
value represents the number of seconds to hold the touch before dragging. The higher the value, the longer the initial press.
I posted an XCUIElement
extension for long swipes in this answer.