我在使用浓缩咖啡库选中复选框时遇到问题。我的复选框包含超链接(可打开网页浏览器的可点击文本(。当我使用onView(withId(R.id.termsAndCondition)).perform(click())
时,它只会打开网络浏览器。
是否有可能在不更改程序代码的情况下检查此 chechkbox?复选框超链接必须可单击
好的,我通过单击复选框的位置 0, 0 找到了一个很好的解决方案
onView(withId(R.id.view)).check(matches(isNotChecked())).perform(clickPercent(0F, 0F));
和点击百分比函数
public static ViewAction clickPercent(final float pctX, final float pctY) {
return new GeneralClickAction(
Tap.SINGLE,
view -> {
final int[] screenPos = new int[2];
view.getLocationOnScreen(screenPos);
int w = view.getWidth();
int h = view.getHeight();
float x = w * pctX;
float y = h * pctY;
final float screenX = screenPos[0] + x;
final float screenY = screenPos[1] + y;
float[] coordinates = {screenX, screenY};
return coordinates;
},
Press.FINGER,
InputDevice.SOURCE_MOUSE,
MotionEvent.BUTTON_PRIMARY);
}