Search code examples
androidappium-android

Is there a way to click on a specific spot on an element?


Given this method (http://appium.io/docs/en/commands/element/actions/click/) only clicks the center of an element, are there means/methods to click on a specific spot on an element?


Solution

  • You can get the current XY coordinate and then compare these coordinates with your SPECIFIC spot. Sample:

    element.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN){
                    if(event.getX()>a && event.getY()<b) {
                        //Your code goes here
                    }
                }
                return true;
            }
    });
    

    where a and b are specific spot in terms of X and Y axis respectively.