tap (Vision)

You can tap an element on the screen using these functions.

Functions

function description
tap(expression) Tap the first element that matches the expression. Scrolling occurs within withScroll function.
tapLast(expression) Tap the last element that matches the expression. Scrolling occurs within withScroll function.
tap(x, y) Tap the coordinates (x, y).
tapWithScrollDown(expression) Tap the first element that matches the expression with scrolling down.
tapWithScrollUp(expression) Tap the first element that matches the expression with scrolling up.
tapWithScrollRight(expression) Tap the first element that matches the expression with scrolling right.
tapWithScrollLeft(expression) Tap the first element that matches the expression with scrolling left.
tapWithoutScroll(expression) Tap the first element that matches the expression without scrolling.
tapCenterOfScreen Tap the center of the screen.
tapCenterOf(expression) Tap the center of the element.
tapItemUnder(expression) Tap the element below of the element of expression.
tapItemOver(expression) Tap the element above of the element of expression.
tapItemRightOf(expression) Tap the element right of the element of expression.
tapItemLeftOf(expression) Tap the element left of the element of expression.
tapTextUnder(expression) Tap the text element below of the element of expression.
tapTextOver(expression) Tap the text element above of the element of expression.
tapOffset(offsetX, offsetY) Tap the offset (in pixels) from the edge of the element.
tapOffsetX(offsetX) Tap the offset (in pixels) from the edge of the element. Offset from right if offsetX > 0; Offset from left if offsetX < 0
tapOffsetY(offsetY) Tap the offset (in pixels) from the edge of the element. Offset from bottom if offsetY > 0; Offset from top if offsetY < 0

Key arguments

argument description
expression Selector expression
language AI-OCR language
last true: Finds the last element
false: Finds the first element(default)
looseMatch true: Applies loose matching to text detection(default)
false: Do not apply loose matching
autoImageFilter true: Applies image filters to improve AI-OCR recognition accuracy
false: Do not apply image filters(default)

Sample code

Getting samples

Tap1.kt

(src/test/kotlin/tutorial/basic/Tap1.kt)

    @Test
    fun tap() {

        scenario {
            case(1) {
                action {
                    it.tap("Network & internet")
                        .tap("Internet")
                    it.pressBack()
                        .pressBack()
                }
            }
            case(2) {
                action {
                    it.tapWithScrollDown("Display")
                        .tapWithScrollDown("Colors")
                    it.pressBack()
                        .pressBack()
                }
            }
        }
    }

    @Test
    fun tapByCoordinates() {

        scenario {
            case(1) {
                action {
                    val v = detect("Network & internet")
                    it.tap(x = v.bounds.centerX, y = v.bounds.centerY)
                }.expectation {
                    it.screenIs("[Network & internet Screen]")
                }
            }
        }
    }

Link