简体   繁体   English

使用UIautomator访问相对布局内的视图

[英]Access the views inside a relative layout using UIautomator

I am trying to automate the GFX benchmark. 我正在尝试使GFX基准自动化。 Where i want user to have the option select the test. 在我希望用户可以选择测试的地方。 But when using the UIAutomator i am not able to find the exact resID to access a particular text.. 但是,当使用UIAutomator时,我无法找到确切的resID来访问特定文本。

GFX

As you can see the Test selection . 如您所见, Test selection i need to click that but i am not able to do so. 我需要单击该按钮,但我无法这样做。

i tried the following code and few variants new UiObject(new UiSelector().className(TextView.class.getName()).textContains("Test")).click(); 我尝试了以下代码和一些变体new UiObject(new UiSelector().className(TextView.class.getName()).textContains("Test")).click();

OK, I was not able to click that particular UI element but i devised a workaround for this. 好的,我无法单击该特定的UI元素,但是为此我设计了一种解决方法。 Basically i just clicked that area based on pixels.Took a screenshot and calculated the percentage positioning of the element and just clicked it. 基本上我只是基于像素单击该区域。拍摄屏幕截图并计算元素的百分比位置,然后单击它。 The code was this 代码是这个

 UiDevice device = getUiDevice(); int height = device.getDisplayHeight(); int width = device.getDisplayWidth(); device.click((int)(width*0.75), (int)(height*.625)); 

Hope this helps anyone stuck on similar issue.Also, if any one has better solution please let me know. 希望这可以帮助任何陷入类似问题的人。此外,如果有更好的解决方案,请告诉我。 :) :)

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

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