0

I have a script to monitor the Notifications screen page.

I can open it via "Culebra" option "UiDevice" -> "Open Notifications".
The notifications error message from some apps have starting characters which are changing, only a constant pattern like "error for" is common but located at different position of the TextView error messages.

Therefore I can't use a regex with the method findViewWithText(regex) as it seems to use a regex match() instead of regex search(). Another solution for my problem is to use traverse() method with my own transform method which can do a regex search() of the view attribute text, but I can't figure out how to pass a parameter like a regex to my own transform method!?

rypel
  • 4,686
  • 2
  • 25
  • 36
AbrtFus
  • 29
  • 7
  • add some code, if you want us to help. There is no way someone could help you with only a wall of text as information. – B. Kemmer May 06 '15 at 09:53
  • sure, solution 1: `t = re.compile('error for')` `error_id = vc.findViewWithTextOrRaise(t)` – AbrtFus May 06 '15 at 10:29
  • solution 2, of course this code does not work and I need to lear how to format code here too :) `def findViewWithSearch(view, regex): # Return the view if text property of the view contains the regex if view.getClass() == 'android.widget.TextView': search_obj = regex.search(view.text()) if search_obj: logger.info("text: %s", view.getText()) regex = re.compile("error for") vc.traverse(transform=findViewWithSearch(regex))` – AbrtFus May 06 '15 at 10:42
  • edit your initial question and add this code. other viewer won't read the comments and just move on to the next question. – B. Kemmer May 06 '15 at 11:31
  • I understand, but I would like to avoid to post wrong codes in the question because those 2 solutions do not work for my case. The simple solution is just to replace the regex match by search of the line code "if root and attr in root.map and regex.match(root.map[attr]):" in the method __findViewWithAttributeInTreeThatMatches() of viewclient.py. But surely it needs first to be discussed with the owner of AndroidViewClient :) – AbrtFus May 06 '15 at 11:51

1 Answers1

1

This works for me to touch on a notification with text USB debugging connected:

vc.findViewWithTextOrRaise(re.compile('.*USB.*'), root=vc.findViewByIdOrRaise('id/no_id/3')).touch()
vc.sleep(_s)

notice this is a modified culebra script, that's why findViewWithTextOrRaise() is using the root argument to limit the search to the subtree which may not be needed in all cases, but it's safer to use.

It's worth to mention, that this works too

vc.findViewWithTextOrRaise(re.compile('.*debugging.*'), root=vc.findViewByIdOrRaise('id/no_id/3')).touch()
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • your example is working perfectly, now I see my mistake, my bad, I forget to add '.*' in my regex, so my regex '.*error for.*' is working fine, I need to re-study regexp :) , thank you very much!!! – AbrtFus May 07 '15 at 08:59