简体   繁体   English

如何使用uiautomator2检测定位的元素是否确实位于顶部并且可点击?

[英]How to detect if a located element is indeed on top and clickable using uiautomator2?

import uiautomator2
device = uiautomator2.connect()
elem = device(resourceId="com.someapp.droid.full:id/publisher_content_row",
            className="android.view.ViewGroup")
elem.click(5)

It is often clicking the bottom-bar or the top bar as the selected item might be hidden behind them occasionally.它经常点击底部栏或顶部栏,因为所选项目有时可能隐藏在它们后面。

Use the Barista library for UI tests, it is the easiest solution and makes everything easier.使用 Barista 库进行 UI 测试,这是最简单的解决方案,使一切变得更容易。 https://github.com/AdevintaSpain/Barista https://github.com/AdevintaSpain/Barista

With Barista, you can do it like this:使用咖啡师,您可以这样做:

assertClickable("Hello world")
assertClickable(R.string.hello_world)
assertClickable(R.id.button)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM