Inspector and recorder

Point at an element on a screenshot to get selectors and code for it, or use the phone while droidline inspect writes the script for you. Optional, and only on your PC.

droidline inspect opens a page in your browser with the phone's screenshot and its element tree side by side. Click an element and it suggests ways to find it, with the line of code for Python, Node.js and the CLI. Turn on the recorder, use the phone as usual, and every tap and every text you type becomes a line of a script.

It is optional. Nothing changes until you start it, it runs only while the command runs, and the page talks only to the Droidline server on your own PC.

Start it

The server must be running (droidline serve). In a second terminal:

droidline inspect
Inspector on http://127.0.0.1:8781
Open it in a browser. Stop with Ctrl+C.

Open that address. Pick the phone at the top if more than one is online, then press Read the screen.

To use another port, pass --listen 127.0.0.1:9000. Keep it on 127.0.0.1: the page can see and control your phones, and it has no password.

Find a selector

Click an element on the screenshot, or a row in the element list. The page outlines it and shows its fields, then Ways to find it:

  • The suggestions that match only this element come first, labelled matches only this. They are ordered the way Finding elements recommends: id, then text, then desc, then queries that combine fields or use the row the element sits in.
  • Suggestions that match several elements come last, with the nth that picks this one.

Choose the command above the list (touch, long_touch, input or get_text) and the language tab, then press Copy. Try it runs that line on the phone and reads the screen again once it settles, so you can see the result.

Record a script

Open the Recorder tab and press Start recording. A red dot appears on the tab. Use the phone as you normally would:

  • A tap becomes touch, and a long press long_touch, with the best selector for what you tapped.
  • Typing into a field becomes one input line with the final text. The tap that opened the keyboard on that field is dropped, because input taps the field itself.
  • Typing into a password field records <password> instead of what you typed. Put the real value in yourself, preferably from an environment variable.

The script starts with launch for the app that was open when you started. Press Stop recording when you are done, choose the language and press Copy.

from droidline import connect

d = connect()
d.launch("com.android.settings")
d.touch({"clickable": True, "has": {"text": "Network & internet"}})
d.touch("id", "search_action_bar")
d.input("id", "search_src_text", "wifi")

Before you run it, read it once:

  • Back and Home are not recorded. Android does not report them to apps. Add d.back() or d.home() where you pressed them.
  • Swipes and scrolling are not recorded. Add scroll_to before a tap on an element further down a list.
  • Add waits where the app loads. A wait_idle() or a wait for the next screen's element keeps the script from running ahead of the phone.

Recording stops by itself after 30 minutes, and nothing is recorded before you press Start. Taps in the Droidline app and on the keyboard are skipped. Text that a script sets with input is not recorded either; only what you type.

Use the recorder from your own tools

The page uses the record command and the action event, which you can use too. Turn recording on with record(True), subscribe to action events, and each event carries what was tapped or typed together with the screen tree at that moment. See record in the command reference and Events in the protocol.