Execute Javascript after page load in WebView
===

I'm making a Mac app and unfortunately have to rely on a webpage to get particular information. I can load the correct webpage by peforming in a call to the WebView's delegate

    [sender setMainFrameURL:@"http://example.com/"];

however, since the page can't load immediately, it will continue with the rest of the function, making later lines like this useless

    [sender stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('example')"];

I know I can use

    - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame

however, this is not a great solution because I will be looking for different information and on different pages. Since this function is a void, I can't return certain information either. I also can't just put in if/else if statements in webViewdidFinishLoadForFrame: because I may want to perform different javascript functions through different calls, for the same page.

Is there a way of making a function to call setMainFrameURL: and then stringByEvaluatingJavaScriptFromString: back to back and have the javascript perform on the correct page?
Thanks.