1

I am trying to search a video in youtube using AndroidViewClient.

package = 'com.google.android.youtube'
activity = 'com.google.android.apps.youtube.app.WatchWhileActivity'

component = package + "/" + activity

device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component)

vc = ViewClient(device, serialno)

search = vc.findViewWithContentDescriptionOrRaise(
    re.compile(u'''Search'''))
search.touch()

search = vc.findViewWithTextOrRaise(re.compile(u'Search\ YouTube'))
search.type('hello')
device.press('KEYCODE_ENTER')

The line :

search = vc.findViewWithTextOrRaise(re.compile(u'Search\ YouTube'))

Throws a view not found error even though there is a view with the exact text.

It works if i dump the window:

vc.dump(window='-1')
search = vc.findViewWithTextOrRaise(re.compile(u'Search\ YouTube'))

Can anyone tell me why this is necessary? How do i recognize that i have to dump the window before finding a view, any tips?

Vikash Balasubramanian
  • 2,921
  • 3
  • 33
  • 74

1 Answers1

3

Every time you do something that changes the screen like

search.touch()

you should invoke

vc.dump(window='-1')

to refresh the internal representation of the screen and being able to search or interact with the new Views that were not there before.

Also, you can use culebra -G to start Culebra GUI and point and click on the UI representation to generate the script, which will generate the dump() when needed.

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