Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildcards on Text Selector for findObjects #6

Closed
bradmill opened this issue Nov 24, 2021 · 2 comments
Closed

Wildcards on Text Selector for findObjects #6

bradmill opened this issue Nov 24, 2021 · 2 comments

Comments

@bradmill
Copy link

Using the example code

oid=$(do_curl -f -X POST "${base_url}/uiDevice/findObject" \ -d "{'text':'${label}'}" | jq .oid)

is there a way that text: could use wildcard / partial match ?

Thanks

@dtmilano
Copy link
Owner

I would do something like this to simplify the use of the API as AndroidViewClient/culebra includes most of the cases:

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from com.dtmilano.android.viewclient import ViewClient


device, serialno = ViewClient.connectToDeviceOrExit()

kwargs2 = {'useuiautomatorhelper': True}
vc = ViewClient(device, serialno, **kwargs2)

for o in vc.uiAutomatorHelper.findObjects(by_selector='text@$[A-Z].*'):
    print(vc.uiAutomatorHelper.getText(o.oid))

This is a simple example based on your request.

Here, we use AndroidViewClient bindings. We request the backend to be CulebraTester2-public by passing {'uiautomatorhelper': True} to the constructor. Notice that the default backend is adb, therefore we need to specify we want uiautomatorhelper (a synonim for CulebraTester2-public) and have the service already running on the device or emulator.

Then, we invoke findObjects (see API) passing a selector text with a value starting with $ which is then interpreted as a regular expression.

We loop over the list of objects found and we invoke getText passing the specific object id.

I run it on an emulator with the Clock as the top Activity to obtain these results:

{'text': 'Alarm'}
{'text': 'Clock'}
{'text': 'Timer'}
{'text': 'Stopwatch'}
{'text': 'Thu, Nov 25'}

If AndroidViewClient does not satisfy your needs my second recommendation would be to use CulebraTester2-client which is the lower level API python client used by AndroidViewClient.

And there's more, if you need bindings for another language other than python you can generate the client from the openapi.yaml spec.

Hope this helps.
Feel free to follow up with more questions here or in Stackoverflow using tag androidviewclient.

Resources

@bradmill
Copy link
Author

Thanks, very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants