问题描述
我试图模仿使用猴亚军和Android ViewClient Android平板电脑的点击。我想点击一个区域/视图具有特定的文本。这里是什么我试图做一个例子:
I'm trying to simulate a click on an Android tablet using monkey runner and Android ViewClient. I want to click on a region/ view which has specific text. Here's an example of what i'm trying to do:
-
我有一个剧本,我进口MonkeyRunner,MonkeyDevice,ViewClient结果
从com.dtmilano.android.viewclient进口ViewClient
结果从com.android.monkeyrunner进口MonkeyRunner,MonkeyDevice
连接平板电脑并创建一个MonkeyDevice对象结果设备= MonkeyDevice.waitForConnection()
Connect the tablet and create a MonkeyDevice objectdevice = MonkeyDevice.waitForConnection()
使用该设备,然后创建一个Android ViewClient对象结果 VC = ViewClient(设备)
Using the device I then create an Android ViewClient objectvc = ViewClient(device)
我打开设置应用程序的平板电脑我 device.startActivity('com.android.settings / .Settings')
I open the Settings app on my tabletdevice.startActivity('com.android.settings/.Settings')
然后我用找到所需的看法:结果 displayView = findViewWithAttribute('文字:多行文字','显示')
I then find the desired view using:displayView = findViewWithAttribute('text:mText', 'Display')
然后我尝试点击该视图(通过模拟触摸事件):结果 displayView.touch()
Then I try to click on that view (by simulating a touch event):displayView.touch()
的问题是,该脚本触摸屏幕的另一部分,在设置应用了WiFi线的左侧部分的某处。
The problem is that this script touches another part of the screen, somewhere in the left part of the WiFi line in the Settings app.
我看着ViewClient源$ C $ C,发现触摸()方法返回(X,Y)的视图坐标,然后使用MonkeyDevice.touch()方法。但是,(X,Y)坐标返回相对于该视图的父。
I looked in ViewClient's source code and found that the touch() method returns the (x,y) coordinates of the view and then uses the MonkeyDevice.touch() method. But the (x,y) coordinates returned are relative to the view's parent.
有谁知道如何得到正确的(X,Y)视图对象的坐标?结果
或至少一种方式来获得视图的父母。
Does anybody know how to get the correct (x,y) coordinates of the view object?
Or at least a way to get the parents of the view.
推荐答案
问题解决了。 AndroidViewClient的最新版本解决了看法我的问题。
Problem solved. The latest version of AndroidViewClient solves my issue with the views.
我可以使用:
view = vc.findViewWithText('Dsiplay')
view.touch()
这篇关于如何点击其中包含指定文本使用monkeyrunner和Android ViewClient视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!