Access UIWebView Content from UI Automation in Instruments

I have a UIWebView in my application that has links inside, which when clicked triggers various actions that must be performed in the application. I would like to verify this with automatic testing so that it can be added to the continuous integration assembly. However, the documentation is pretty rare for UIAWebView , and I tried not to work to get this to work.

Has anyone had any success interacting with links inside a UIWebView so that you can verify the correctness of their actions?

+6
source share
1 answer

Could not find a way to iterate / access links in UIWebView, but will this work for you? Access to page source:

 NSString *source = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('html')[0].outerHTML"]; 

then find the tags that you think are links (e.g. href = ...)

Then you still need to β€œclick” these links. Is it enough for you to go to the URL provided in the link? If so, just use loadRequest for this. If you need more advanced behavior (for example, make sure javascripts are running correctly), you will need to do more magic to parse them and execute them using stringByEvaluatingJavaScriptFromString.

+1
source

Source: https://habr.com/ru/post/890061/


All Articles