首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PerformException:执行‘单击’时出错

PerformException:执行‘单击’时出错
EN

Stack Overflow用户
提问于 2015-04-22 10:01:25
回答 11查看 57.7K关注 0票数 70

当我运行android espresso测试时,我得到一个错误:

在id为: is <2131034173>的视图‘com.google.android.apps.common.testing.ui.espresso.PerformException:’上执行‘单击’时,

视图出错。

我的代码很简单:

代码语言:javascript
复制
onView(withId(R.id.btn)).perform(click());

但是下面的代码没有错误:

代码语言:javascript
复制
onView(withId(R.id.btn)).check(matches(isDisplayed()));

我找不到它发生的原因。

EN

回答 11

Stack Overflow用户

发布于 2015-10-02 04:43:25

诀窍是读取错误的完整堆栈跟踪。在中间,有一些关键的信息,比如:

代码语言:javascript
复制
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
at least 90 percent of the view's area is displayed to the user.
Target view: "ImageView{id=2131492903, res-name=button_hamburger, desc=opens the side drawer, visibility=VISIBLE, width=64, height=64, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=6.0, y=6.0}"

这详细解释了错误。

票数 124
EN

Stack Overflow用户

发布于 2015-04-22 17:07:39

尝试确保软键盘未显示。它可以很容易地用closeSoftKeyboard ViewAction关闭。

此外,请确保禁用了系统动画。在“设置”“->开发选项”下,关闭以下选项:

动画窗口动画scale

  • Transition动画缩放
  • 动画持续时间缩放

此外,这可能是由来自其他应用程序的ANR对话框引起的。

据报道,here也有一个问题。

票数 38
EN

Stack Overflow用户

发布于 2016-04-20 05:59:07

我也有同样的问题,因为软键盘与元素重叠。我使用scrollTo(),然后单击()来解决这个问题。

代码语言:javascript
复制
onView(withId(R.id.btn))
     .perform(scrollTo())
     .perform(click());

如果以上内容不起作用,请先尝试添加以下内容:

代码语言:javascript
复制
onView(withId(R.id.myEditText)).perform(closeSoftKeyboard());
票数 29
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29786413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档