Hi All,
I am in the process of developing an feature in MAC which is already developed on iOS.
In MAC, I load an web page on a WebView which contains some fields where I need to provide my credetials to authenticate and after successful authentication, the webpage gives me some response which I need to parse for it's data.
Below is the format of the data sent by the server on my iPhone
The code that I used on iPhone to print contents in html for debugging is provided below.
The problem that I am currently facing in MAC platform is that I am not able to parse the contents of the "decryptKey" key which is defined as of type 'hidden'.
I use the below mentiond code to print the contents of WebView on MAC and find that it does not print the tags whose type is declared as "hidden".
I am not sure if the code to display the contents of UIWebView and WebView are equivalent (if not equivalent, it explains why the hidden types are not displayed).
Below is the code snippet on MAC that I use to parse the fields where I am facing some issue.
Not sure why I am able to parse encryptedData tag but not decryptKey tag.
Am I doing something wrong with respect to parsing of WebView data?
I am in the process of developing an feature in MAC which is already developed on iOS.
In MAC, I load an web page on a WebView which contains some fields where I need to provide my credetials to authenticate and after successful authentication, the webpage gives me some response which I need to parse for it's data.
Below is the format of the data sent by the server on my iPhone
Code:
<html><head>
<meta name="HandheldFriendly" content="True">
<meta name="viewport" content="width=device-width, initial-scale=1,,user-scalable=no">
<meta http-equiv="cleartype" content="on">
<title>Getting Started</title>
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js"></script><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([ '_setDomainName', 'none' ]);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl'
: 'http://www')
+ '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body class="background">
<div>
<div class="boxcenter">
<div id="pushme_2"></div>
<div id="pushme_15"></div>
<p class="label-text">
Almost done.
</p>
</div>
<div>
<input id="encryptedData" type="hidden" value="InPU4j5rmkC/eQwlInfSa54cOlnRQRiIQMjlFZ0QJQbsuUhuEAAUnUqmLFLKoyRGzBB3Z8lEcRPbNQk5f6Zrjmp+S/96xU++URuYP1N0oQ03V2dGWJ=">
<input id="decryptKey" type="hidden" value="CDtMmcVcXJhp5fcrW5yQqrTdAPZiYPtjQx9+">
</div>
</div>
</body></html>
Code:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *test = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
NSLog(@"%@", test);
}
The problem that I am currently facing in MAC platform is that I am not able to parse the contents of the "decryptKey" key which is defined as of type 'hidden'.
I use the below mentiond code to print the contents of WebView on MAC and find that it does not print the tags whose type is declared as "hidden".
Code:
NSLog(@"In Mac: %@", [(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText]);
I am not sure if the code to display the contents of UIWebView and WebView are equivalent (if not equivalent, it explains why the hidden types are not displayed).
Below is the code snippet on MAC that I use to parse the fields where I am facing some issue.
Code:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
id win = [webView windowScriptObject];//webView is the WebView object.
id location = [win valueForKey:@"encryptedData"];
NSString *activationString = [location valueForKey:@"value"];//Returns valid string.
id win2 = [webView windowScriptObject];
id keyLocation = [win2 valueForKey:@"decryptKey"];
NSString *decryptionKey = [keyLocation valueForKey:@"value"];//does not return the string.
}
Am I doing something wrong with respect to parsing of WebView data?