gpt4 book ai didi

java - 检查对话框是否可见 - Espresso

转载 作者:行者123 更新时间:2023-12-02 10:35:09 24 4
gpt4 key购买 nike

我在 Stackoverflow 上发现了类似检查对话框何时可见的内容:

 onView(withText("Yes"))
.inRoot(isDialog())
.check(matches(isDisplayed()))
.perform(click());

当然,如果带有"is"按钮的对话框可见,则这有效,但在不同的情况下,如果对话框不可见,我会崩溃:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "Yes"

那么如何写如果对话框存在则点击yes,如果不存在则什么都不点击呢?

最佳答案

你可以试试这个:

  onView(withText("Yes")).inRoot(isDialog()).withFailureHandler(new FailureHandler() {
@Override
public void handle(Throwable error, Matcher<View> viewMatcher){

}
}).check(matches(isDisplayed())).perform(customClick());

//if dialog is visible, perform click, otherwise do nothing.

关于java - 检查对话框是否可见 - Espresso,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53351111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com