0

I have a pretty basic script where I intend for the application to drag 3 times, and then touch a button. The application drags three times perfectly, but then get's an error when I add in the touch code.

Code:

device, serialno = ViewClient.connectToDeviceOrExit())
device.drag((120, 220), (300, 220), 1, 20)
MonkeyRunner.sleep(5)
device.drag((120, 220), (300, 220), 1, 20)
MonkeyRunner.sleep(3)
device.drag((120, 220), (300, 220), 1, 20)
temp = device.findViewWithText('Lesson 1')
temp.touch()

Error:

line 34, in <module>
    device, serialno = ViewClient(*ViewClient.connectToDeviceOrExit())
TypeError: 'instance' object is not iterable

New Code:

device, serialno = ViewClient.connectToDeviceOrExit()
temp = device.findViewWithText('Lesson')

New Error:

    temp = device.findViewWithText('Audiobooks')
AttributeError: 'com.android.monkeyrunner.MonkeyDevice' object has no attribute 'findViewWithText'
EGHDK
  • 17,818
  • 45
  • 129
  • 204

1 Answers1

0

There is an extra ')' at the end:

device, serialno = ViewClient.connectToDeviceOrExit()) 

I guess you mean

device, serialno = ViewClient.connectToDeviceOrExit()

New code

The problem with your new code

temp = device.findViewWithText('Lesson')

is that findViewWithText() is a method in ViewClient class not in MokeyDevice as the error tells you:

AttributeError: 'com.android.monkeyrunner.MonkeyDevice' object has no attribute 'findViewWithText'

So the correct code is:

vc = ViewClient(device, serialno)
temp = vc.findViewWithText('Lesson')

Take a look at the examples and you'll have all your questions answered.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134