Reputation: 3733
Trying to use MonkeyRunner to perform some testing and want to use AndroidViewClient to work with EditText widgets.
I believe I am using AndroidViewClient correctly (relevant stuff below), findViewByIdOrRaise()
is always throwing an error. I've tried every variant of specifying an ID that came to mind.
Here is a snippet from my activity's XML:
<EditText
android:id="@+id/someText"
... >
<requestFocus />
</EditText>
<!-- Yes, that is the actual id of my EditText -->
In my MonkeyRunner script I have the following:
device, serialno = ViewClient.connectToDeviceOrExity(serialNo=myDeviceId)
vc = ViewClient(device=device, serialno=serialno)
device.installPackage(apkPath)
device.startActivity(component='com.app.name/com.app.name.ActivityName')
editTextId = 'id/someText'
try:
someText = vc.findViewByIdOrRaise(editTextId)
someText.touch()
someText.type('Derp derp derp')
except ViewNotFoundException, e:
# The comma above is because Jython 2.5.3 does not support the AS keyword
print ' [*] %s' % (e)
Of course, my code is doing a little more (but not much) than what is shown. I stripped out everything that didn't seem relevant. I will gladly put it all up there, but didn't want to start off with code vomited all up in here.
I've looked at everything I could find on the topic:
Any ideas on what I'm doing wrong?
Upvotes: 0
Views: 646
Reputation: 1691
The latest version of ViewClient gives a unique id to each view in the app. The id format is i/no_id/number. You could use a script called dump.py to see the current views. It is located in the examples folder in ViewClient.
Upvotes: 2