Home » Android » Android get text from browser

Android get text from browser

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to get text from browser by using uiautomator

How can I do it?

I’ve parsed structure of chrome and there is only android.View.view
I’ve tried to use getText() function, but it’s not helped.
Any help appreciated.

Maybe somebody know how can I do it by calling some chrome instance… or with any other method.

Any solution, with info, how to save android browser page as html/text will be enough, or how to select whole page. (except touching/long pressing text).

How to&Answers:

UiDevice.getLastTraversedText() is the only way I know to get highlighted text in webview. I am also looking for a better way to test webview on Android.

Answer:

Weirdly, UiDevice.getLastTraversedText() has never worked for me. Since Android 4.4 though, the elements are exposed as the android.view.View with its text or function as content descriptors. Does not work all the time, but it is a large improvement.

Answer:

use dumpWindowHierarchy() Method of UiDevice class to save current activity properities to file, the default location is “/data/local/tmp”.Then read that file using file operations.

Second way of getting current activity properities :
1. Use “adb shell uiautomator dump /data/local/tmp/view.xml” to get screen properities.
2. Pull the file to computer machine using adb pull command and read that file.