I have a UIViewController that has a WKWebView that loads a particular view with a button that needs to be clicked automatically. To tackle this, I used the WKNavigationDelegate protocol function didFinish and an utilizing WKWebView's evaluateJavaScript method. Here is my implementation
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.getElementsByClassName('myButtonClass')[0].click()") { (result, error) in
print("ERROR: \(error)")
print("RESULT: \(result)")
}
}
So once the page is loaded, I am attempting to click a certain button on the screen (keep in mind, there is only one button with this class name on this particular page view). When this code runs, both result and error get printed out, and both of them are nil. Yet, the button is not clicked and WKWebView never redirects to the link the button links to.
How is it possible that there is no error but nothing happens?
Am I missing some sort of navigation set up or something?