I've a p tag with id test in my webpage, when I put it as follows everything works well.
html,
<p id="test">hhhhhhhhhhhh</p>
<body ng-app="home" ng-controller="HomeController" style="min-height:700px;">
<printerinfo></printerinfo>
</body>
swift3,
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.wk.evaluateJavaScript("document.getElementById('test').innerHTML;") { (result, error) -> Void in
->
if error != nil {
print(error)
}
print(result)
}
}
While I move the p tag to template printerinfo, I get
UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=TypeError: null is not an object (evaluating 'document.getElementById('test').innerHTML')
most of the cases, and the remain cases works well with result Optional(hhhhhhhh)
And here is the ios wkwebview page content viewed from Safari technology Preview's develpe > iphone device name's window. And I can access the innerHTML from the console.
For now I guess that the evaluateJavaScript has executed before the anjular has finished feeding the webpage.