I would still like to learn the Selenium interface from Python. But I found an effective way to get a clear idea of how the application was laid out, and it's pretty easy to understand how to write Selenium tests.
First, run the application, either on a real device connected to an Android development computer, or in an emulator. Basically, if you run adb devices , you want to see one device that launches your application. Then run the uiautomatorviewer tool, and then click the Device Screenshot toolbar icon. (There are only two icons on the toolbar: the first Open icon looks like a folder with files, and the one you want looks like a stack of mobile phones.)
Once you do this, an image of your application will appear with a screenshot on the left and an overview tree on the right. The diagram shows all the controls of the application, as well as their text labels, if any, and other information (for example, for this element true or false for this control).
One caveat: the controls are numbered, but in Selenium bindings, the numbers may not be the same. In the ApiDemos application ApiDemos the Graphics button has an index number of 4, since it is the fifth button, but I had to use index 5 to access it in its position. Index 0 was not a clickable object containing the text "API Demos" in another FrameLayout object making up the title for the screen.
So, I was able to make this change in the android.py script:
#elem = driver.find_element_by_name('Graphics') elem = driver.find_elements_by_tag_name('TextView')[5]
Comment on the call to driver.find_element_by_name() , and instead find the sixth TextView in the entire application. This is not best practice, but it shows that the results of the uiautomationviewer allow me to view the information I need to know about the controls.
Now I know enough to do a little introspection:
for elem in driver.find_elements_by_tag_name('TextView'): if elem.text == "Graphics": break else: print("Could not find desired item")
This is no better than just calling driver.find_element_by_name() , but it shows that I'm on the right track.
uiautomatorviewer is a practical solution to my problem. If you have pure-Python, let me know.