facebook / chisel

Chisel is a collection of LLDB commands to assist debugging iOS apps.
MIT License
9.12k stars 804 forks source link

Search For Text Within Views #223

Closed danielchangsoojones closed 6 years ago

danielchangsoojones commented 6 years ago

Is there a command to search a string that I see on my button (i.e. "Enter Your Email Address") and then it will return the name and address of the View that it came from?

Example: I search "Enter Your Email Address" it goes through all UILabels, UITextViews, UIButtons, etc. to find any button that has that "Enter Your Email Address" Then, it returns all the names and addresses that had this string as their text.

This would make it really easy to find the button on a view. Thank you for this project. It is great! I looked through all documentation to find this, but I may be missing something because I couldn't find it.

Also, is there a way to get the actual variable name of a view from an address? Example: Search 0x7f8588e1e8a0 and then it returns "doneButton" as the variable name of that button.

kastiglione commented 6 years ago

You could try fa11y (run help fa11y for more info). This obscurely named command is f + a11y where f is for "find" and a11y is an abbreviation for "accessibility". This command searches the accessibility labels of views.

Also check out taplog, which waits for the next tap and prints out the view that was tapped. If you run taplog and then tap the button, and its address will be printed.

danielchangsoojones commented 6 years ago

Wow, taplog is a very nice command. If I don't have accessibility labels set for my view then will it not find anything? Aren't accessibility labels when you are trying to help impaired people (blind, deaf, etc.) use the app and you have to manually set them?

kastiglione commented 6 years ago

Accessibility labels are set by default for buttons, labels, and text views. For your example, the button accessibility label can be expected to match the button's text.

kastiglione commented 6 years ago

A last approach to doing this is to run pviews, which will print out the entire view hierarchy. Then, from the lldb console, use Command-F to search for the view you're interested in. Or, instead of Command-F, Xcode has a Filter search field at the bottom right of the console, which will show only lines that match the filter text.

screen shot 2018-01-26 at 10 03 15 am