Search code examples
iosui-automationios-ui-automationxcuitest

xcuitest- Trying to tap on a link within a linklabel


I am trying to tap on a link within a link label. Using the recorder I have this code for the tap event

let link = XCUIApplication().scrollViews.otherElements.links["link here"]

link.tap() does not tap on the link correctly. The link is at the end of the text, how would I be able to tap that part of the label? It seems like XCUITest taps the start of the text which doesnt have the link


Solution

  • Seems like it may be an accessibility container issue. However one work around is to compute the coordinate relative to the UI element you can access with XCUIApplication.

    let coordinate = CGVector(dx: 0.1, dy: 0.1) //Enter your values for x / y
    someElement.coordinate(withNormalizedOffset: coordinate).tap()
    

    I usually just use trial and error to compute the coordinates. However, you can use the accessibility inspector and debug prints if you need an extra precise press.