uiautomator怎么点击屏幕指定位置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uiautomator怎么点击屏幕指定位置相关的知识,希望对你有一定的参考价值。

参考技术A 264768502 · #1 · 2 月前
一种,你可以用flingForward()代替drag,不过你的控件必须是UiScrollable的
另一种,重写swipe
extras\android\m2repository\com\android\support\test\uiautomator\uiautomator-v18\2.1.2\uiautomator-v18-2.1.2-sources.jar!\android\support\test\uiautomator\InteractionController.java

public boolean swipe(int downX, int downY, int upX, int upY, int steps, boolean drag)
boolean ret = false;
int swipeSteps = steps;
double xStep = 0;
double yStep = 0;

// avoid a divide by zero
if(swipeSteps == 0)
swipeSteps = 1;

xStep = ((double)(upX - downX)) / swipeSteps;
yStep = ((double)(upY - downY)) / swipeSteps;

// first touch starts exactly at the point requested
ret = touchDown(downX, downY);
if (drag)
SystemClock.sleep(mUiAutomatorBridge.getSystemLongPressTime());
for(int i = 1; i < swipeSteps; i++)
ret &= touchMove(downX + (int)(xStep * i), downY + (int)(yStep * i));
if(ret == false)
break;
// set some known constant delay between steps as without it this
// become completely dependent on the speed of the system and results
// may vary on different devices. This guarantees at minimum we have
// a preset delay.
SystemClock.sleep(MOTION_EVENT_INJECTION_DELAY_MILLIS);

if (drag)
SystemClock.sleep(REGULAR_CLICK_LENGTH);
ret &= touchUp(upX, upY);
return(ret);

把SystemClock.sleep(REGULAR_CLICK_LENGTH);这一行的REGULAR_CLICK_LENGTH改成mUiAutomatorBridge.getSystemLongPressTime()

第二种我没试过,仅仅理论上可行

以上是关于uiautomator怎么点击屏幕指定位置的主要内容,如果未能解决你的问题,请参考以下文章

appium和uiautomator的区别

如何用javascript点击指定的位置

uiautomator - 当我验证每个列表项中的文本时,无法让 ListView 滚动。当我点击屏幕上的最后一个项目时它就失败了

python uiautomator2 第二个toast怎么写

uiautomator中InteractionController学习笔记

模拟鼠标点击而不移动光标