gpt4 book ai didi

earlgrey - 如何检查元素是否存在于 UI 层次结构中?

转载 作者:行者123 更新时间:2023-12-01 12:27:09 27 4
gpt4 key购买 nike

如何检查元素是否存在于 UI 层次结构中?如果元素不存在,我不希望 EarlGrey 失败,只是检查它是否存在,我需要这个用于 UITableView,我必须不断滚动到顶部并向下滚动搜索元素,但该元素有时已经在当前 View 中开始.

最佳答案

EarlGrey 支持错误 API:当 EarlGrey API 采用 NSError 引用时,API 在失败时不会抛出错误引用,而是用相应的错误填充错误引用。例如,使用此代码检查 View 层次结构中是否存在元素(并根据该信息采取行动):

NSError *error;
[[EarlGrey selectElementWithMatcher:grey_fooElementMatcher()]
assertWithMatcher:grey_notNil() error:&error];

if (error && [error.domain isEqual:kGREYInteractionErrorDomain] &&
error.code == kGREYInteractionElementNotFoundErrorCode) {
// Element doesn’t exist.
} else if (!error) {
// Element exists.
}

关于earlgrey - 如何检查元素是否存在于 UI 层次结构中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38233160/

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