dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.61k stars 344 forks source link

How to get the clickable element #280

Closed Witcher1499 closed 2 years ago

Witcher1499 commented 4 years ago

Hi! How to get the clickable element data in dump function. (or) How else way to get the clickable element data.

dtmilano commented 4 years ago

View[ class=android.widget.LinearLayout index=3 text= resource-id= class=android.widget.LinearLayout package=com.android.settings content-desc= checkable=false checked=false clickable=true enabled=true focusable=true focused=false scrollable=false long-clickable=false password=false selected=false bounds=((0, 767), (1080, 967)) uniqueId=id/no_id/14 ] parent=androidx.recyclerview.widget.RecyclerView

where clickable=true.

dtmilano commented 4 years ago

This was a piece of the output of dump -a

Witcher1499 commented 4 years ago

Thank you so much.. But, this tool not working in android version 8 and above. What should I do for the solution?

dtmilano commented 4 years ago
$ adb shell getprop ro.build.version.sdk
29
$ dump --version
dump version 20.0.0b4
$ dump --all |  | grep 'clickable=true'
      View[ class=android.view.View index=0 text= resource-id=com.google.android.apps.nexuslauncher:id/mic_icon class=android.view.View package=com.google.android.apps.nexuslauncher content-desc=Voice search checkable=false checked=false clickable=true enabled=true focusable=false focused=false scrollable=false long-clickable=false password=false selected=false bounds=((864, 1697), (1011, 1844)) uniqueId=id/no_id/31 ]   parent=android.widget.FrameLayout
Witcher1499 commented 3 years ago

Thank you so much.. sorry for the trouble! Often this problem comes up,

**raise ValueError("received does not contain valid XML: " + receivedXml)
   ValueError: received does not contain valid XML: Killed** 

What should I do for the solution???

dtmilano commented 3 years ago

The issue is that AndroidViewClient depends on uiautomator dump's output and something failed in uiautomator. You can verify that by running

$ adb shell uiautomator dump

and it would print

Killed

Going to home or other activity and back to your app sometimes help and solves the problem.

Another alternative is to use CulebraTester2-public (a new backend which is under development) that doesn't have this problem or limitation.

Witcher1499 commented 3 years ago

What is the meaning for "vc.dump(window=-1)"?

dtmilano commented 3 years ago

You can see the docs

    def dump(self, window=-1, sleep=1):
        '''
        Dumps the window content.
        Sleep is useful to wait some time before obtaining the new content when something in the
        window has changed.
        @type window: int or str
        @param window: the window id or name of the window to dump.
                    The B{name} is the package name or the window name (i.e. StatusBar) for
                    system windows.
                    The window id can be provided as C{int} or C{str}. The C{str} should represent
                    and C{int} in either base 10 or 16.
                    Use -1 to dump all windows.
                    This parameter only is used when the backend is B{ViewServer} and it's
                    ignored for B{UiAutomator}.
        @type sleep: int
        @param sleep: sleep in seconds before proceeding to dump the content
        @return: the list of Views as C{str} received from the server after being split into lines
        '''
Witcher1499 commented 3 years ago

Not Working click function in android version 8 and above. Particularly Mi 5 and Mi 5 Note pro?