模拟器上dumpsys活动中的按钮位置不正确


  1. 在一个新的虚拟设备(Pixel 4,api版本30,Android 11(上,我打开Chrome,然后点击"接受&继续";在欢迎使用Chrome屏幕上
  2. 在这一点上,Chrome in处于"打开"状态;打开"同步";屏幕上;不,谢谢;按钮
  3. 然后我切换到mac上的终端并运行adb shell dumpsys activity top

结果包含以下行:

org.chromium.chrome.browser.signin.AccountSigninView{1080,0-2160,1977}
android.widget.LinearLayout{0,1790-1080,1977 #7f0b009c app:id/button_bar}
org.chromium.ui.widget.ButtonCompat{44,44-299,143 #7f0b02d1 app:id/negative_button}

AccountSigninView的坐标1080,0-21601977在屏幕外,但该按钮在屏幕上可见。这种行为没有在我的手机上重现。

问题:

  1. 我怎么能理解这个按钮实际上是可见的,而不是在屏幕之外
  2. 如何调整模拟器,使其具有与我的普通手机相同的行为

更新1:

我试着运行adb shell uiautomator dump,尽管在屏幕边界之外没有控件,但按钮的坐标为零。

<node
resource-indroid.chrome:id/negative_button"
...
bounds="[0,0][0,0]"/>

我不知道如何解析dumpsys acticity top的输出,但1080和2160是布局的上y坐标和下y坐标。至于另外两个数字,我不知道如何解析它们
如果要获得任何视图的边界,最好使用uiautomator dump命令。它输出一个xml文件,您可以在其中找到屏幕中任何视图的边界。

您可以尝试使用uiautomator或其他后端(如果可用(的AndroidViewClient/culebra,也可以对坐标进行一些调整,例如运行

dump --bounds

在类似的情况下(Chrome已经安装(,会给出

...
android.widget.Button com.android.chrome:id/signin_promo_choose_account_button Choose another account ((143, 1900), (937, 2032))
...

因此,如果你想点击按钮,使用AndroidViewClient,你可以简单地进行

vc.findViewWithTextOrRaise(u'Choose another account').touch()

最新更新