To simulate the touch you will need to write a javascript function in your web page that can click the button on your behalf.
Let's assume the button on the website loaded in the iFrame is coded as the following:
<a href="#" id="MagicButton" onclick="targetFunction();">Click Me!</a>
And the iFrame is coded like so in your webpage:
<iframe id="MyIFrame" src="http://www.stackoverflow.com" width="200" height="200"></iframe>
In your web page add the following javascript function to call the click event on the embedded button:
<script>
function myJavaScriptFunction(){
//get handle for the iFrame element
var iFrame = document.getElementById('MyIFrame');
var htmlDoc = iFrame.contentDocument ? iFrame.contentDocument : iFrame.contentWindow.document;
var magicButton = htmlDoc.getElementById('MagicButton');
magicButton.click();
}
</script>
Going back to your Swift code, you will need to use the following API:
func evaluateJavaScript(_ javaScriptString: String,
completionHandler completionHandler: ((AnyObject?,
NSError?) -> Void)?)
You can execute your javascript function by calling the following function after the page has loaded:
myWKWebview.evaluateJavaScript("myJavaScriptFunction(argument1, argument2);",
completion:{ _ in })