views:

189

answers:

1

Howdy,

I looking into making a kind of robot testing browser. Like Selenium, but one that we can use to make full integration tests of our site. I'm wondering if it's possible to create a Cocoa app that loads up a web page in a WebView and they programmatically sends click events. I realize you could use:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

To send js click evenets, but it would be better if you could send click events to the DOMElements themselves. That way you could test file uploads and other elements that can't be accessed via javascript like flash. Does anyone know if this is possible?

Thanks in advance for the help, JP

+2  A: 

You can obtain DOMNode* objects corresponding exactly to JavaScript Node objects by using a WebView's -windowScriptObject method (that returns the WebScriptingObject* that corresponds to the JavaScript window object) or any frame's -DOMDocument method to return that frame's JavaScript document method.

Example:

DOMDocument* d = [[webView mainFrame] DOMDocument];
[[[d getElementsByTagName:@"a"] item:0] click];
millenomi