Android - check if element exists inside WebView (in DOM)
Is there an easy way to check if a specific item (given its id) exists on a webpage loaded inside a WebView.
I know that in Javascript we can use document.body.contains(element);
to check if this element is present or not.
How can I use this in my Android application thread to find out if an element is present or not (before making some other assertions based on the element's existence)?
+3
source to share
1 answer
As you can see there , it is easy to know if the webview contains a specific string.
So, if your webview only contains unique strings, it is possible to test it with the following:
String string = "text you want to find";
webview.findAll(string); //works for API levels 3 - 16
webview.findAllAsync(string); //works for API levels 16 and up
But this is very harmful, because it is often impossible to make all the lines in the user interface unique.
-1
source to share