uiautomator点击,没有文字或内容说明一个的ImageButton [英] uiautomator click on a ImageButton with no text or content-desc
问题描述
在4.2.2模拟器,在现在从音乐播放屏幕,我们有preV,播放和下一ImageButtons。不幸的是这3个按钮没有文字或contet-递减值。
On 4.2.2 emulator, in Now Playing screen from Music, we have the prev, play and next ImageButtons. Unfortunately these 3 buttons have no text or contet-desc values.
我想点击其中一个,我想答案就在于这样的:
I want to click on one of them and I think the answer lies in something like:
UiObject relLayout = new UiObject(new UiSelector()
.className("android.widget.LinearLayout").index(1));
relLayout.click();
但有几个的LinearLayout在此屏幕上,我不知道如何选择特定的LinearLayout。在code以上剪断将美元洗牌p $ PSS,因为它也是包含3图像按钮(库,随机播放和重复)一个LinearLayout中。
But there are several LinearLayout in this screen and I don't know how to select a specific LinearLayout. The code snipped above will press on shuffle as it is also a LinearLayout that contains 3 image buttons(library, shuffle and repeat).
我们知道我们的LinearLayout的唯一的事情是,它是孩子,与指数5,另外的LinearLayout这是孩子,索引为0,一个的FrameLayout这是孩子,索引为0,一个LinearLayout中的哪是孩子,索引为0,一个的FrameLayout的。
The only thing we know about our LinearLayout is that it is the child, with index 5, of another LinearLayout which is the child, with index 0, of a FrameLayout which is the child, with index 0, of a LinearLayout which is the child, with index 0, of a FrameLayout.
问题是,我们怎么能知道UiSelector寻找一个特定的LinearLayout?
The question is how can we tell UiSelector to look for a certain LinearLayout?
谢谢,
亚历
推荐答案
在这样的情况下,我通过边界点击
。这可能会导致问题原因更改设备大小,边界会发生变化。所以我得到了屏幕高度,使你知道你使用的设备,然后通过边界点击
。你可以找到你的边界
通过 uiautomatorviewer
In situations like this, I click by bounds
. This is can cause problems cause when you change device sizes, the bounds will change. So I get the screen height so you know which device your using, then click by bounds
. You can find your bounds
via uiautomatorviewer
int height = UiDevice.getInstance().getDisplayHeight();
if(height == THE_SIZE_EXPECTED){
UiDevice.getInstance().click(int_x, int_y);
} else if (height == ANOTHER_SCREEN_HEIGHT_OPTION){
UiDevice.getInstance().click(int_x, int_y);
}
希望这有助于
这篇关于uiautomator点击,没有文字或内容说明一个的ImageButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!