So with the new xcode update apple has revamped the way we do UI testing. In instruments we used java script function \"isVisible\" to determine if our targeted element is visib
Update to @ravisekahrp's answer for newer Swift:
extension XCUIElement {
func isVisible() -> Bool {
if !self.exists || !self.isHittable || self.frame.isEmpty {
return false
}
return XCUIApplication().windows.element(boundBy: 0).frame.contains(self.frame)
}
}
extension XCTestCase {
func scrollToElement(_ element: XCUIElement) {
while !element.isVisible() {
let app = XCUIApplication()
let startCoord = app.tables.element.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5))
let endCoord = startCoord.withOffset(CGVector(dx: 0.0, dy: -262))
startCoord.press(forDuration: 0.01, thenDragTo: endCoord)
}
}
}