Currently I'm trying to fill all fields from a form using Python + uiautomator
My Code:
d = UIDevice(adb.deviceList[0].device)
last_item_exists = d(text='Memo').exists
while not last_item_exists:
print "Searching for fields on screen"
fields = d(className = 'android.widget.EditText', focusable = True)
for field in fields:
if not (field.text == '0' or field.text == '50'): #Skip fields with 0 or 50
print "Writing on the field"
field.click()
d.press(0x0000001d, 0x00001000)
d.press('del')
field.set_text('50')
else:
print "Skipping field"
print "Searching for Memo field"
last_item_exists = d(text='Memo').exists
print "Scrolling down"
d(scrollable=True).fling()
d(text='Confirm').click()
The Problem:
Depending on device resolution, this error may occur:
uiautomator.JsonRPCError: JsonRPC Error code: -32002, Message: com.android.uiautomator.core.UiObjectNotFoundException: UiSelector[CLASS=android.widget.EditText, INSTANCE=9, FOCUSABLE=true, RESOURCE_ID=com.salab.ABRT:id/task_info_item_count]
This is happening, because when I click on the last visible field field, the screen sometimes scrolls down a bit and the top field is not visible anymore.
Is there a workaround for this kind of problem, or I must change my logic(Can't think about anything right now...) ?
UiAutomator only sees what is visible on the screen at each moment. So if you scroll down (or the app does) then it can't interact with it.
You either change your logic or you swipe the screen up and down verifying if everything is filled and, if not, fill it.
User contributions licensed under CC BY-SA 3.0