i have a UIWebView which acts like an internet browser and loads the HTML of the webpages that it is at.
in the webViewController, the method webViewDidFinishLoad, w
I had some problems with finding the fields, so I adapted the code to target the fields more specific:
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
NSString *savedUsername = @"username";
NSString *savedPassword = @"pass";
if (savedUsername.length != 0 && savedPassword.length != 0) {
NSString *loadUsernameJS = [NSString stringWithFormat:@"var inputFields = document.getElementsByTagName('input'); \
for (var i = inputFields.length >>> 0; i--;) { if(inputFields[i].name == 'username') inputFields[i].value = '%@';}", savedUsername];
NSString *loadPasswordJS = [NSString stringWithFormat:@" \
for (var i = inputFields.length >>> 0; i--;) { if(inputFields[i].name == 'password') inputFields[i].value = '%@';}", savedPassword];
//autofill the form
[theWebView stringByEvaluatingJavaScriptFromString: loadUsernameJS];
[theWebView stringByEvaluatingJavaScriptFromString: loadPasswordJS];
}
return [super webViewDidFinishLoad:theWebView];
}