I'm loading html page inside of WKWebView and I need to click on a link. For example. loading apple.com
override func viewDidAppear() {
super.viewDidAppear()
webView.load(urlString: "https://www.apple.com")
}
and locating the links to click:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!){
webView.evaluateJavaScript("document.getElementsByClassName('cta-links')[0].innerHTML") { (result, error) in
if error != nil {
print(error?.localizedDescription ?? "")
}
if result != nil{
print("code with links \(result)")
}
}
}
The output I'll get is:
<a href="/us/shop/goto/buy_iphone/iphone_xr" class="cta more" aria-label="Buy now with trade in" data-analytics-title="buy now with trade-in" data-analytics-region="buy">Buy<span class="visuallyhidden">with trade in</span></a>
<a href="/us/shop/goto/trade_in" class="cta more" aria-label="Learn more about trade in" data-analytics-title="Learn more about trade-in" data-analytics-region="learn more">Learn more</a>
But my question to you guys is how can I click on of those links for example on this link:
<a href="/us/shop/goto/trade_in" class="cta more" aria-label="Learn more about trade in" data-analytics-title="Learn more about trade-in" data-analytics-region="learn more">Learn more</a>
There is a way to click on that link either with javascript or any other way in swift?
I'll really appreciate your help.