开发者

Accessing UIWebView contents from UI Automation in Instruments

I have a UIWebView in my application which has links inside that when clicked cause different actions to be carried out in the applic开发者_开发问答ation. I'd like to be able to test this with automated testing so it can be added to a continuous integration build. However, the documentation is rather sparse for UIAWebView and I've tried to no avail to get this to work.

Has anyone had any success interacting with links inside a UIWebView so you can check that their action is correct?


Couldn't find a way to iterate/access links in a UIWebView but would this work for you? Access the page source with:

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

then look for the tags that you consider to be links (e.g. href=...)

Then you still need to be able to "press" those links. Is it enough that you navigate to the url given in the link? If so, just use loadRequest to do so. If you need more advanced behaviour (for example make sure correct javascripts are run), you'll need to do more magic to parse those and execute them with stringByEvaluatingJavaScriptFromString.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜