ios - Swift - programmatically click on point in screen -


tl;dr- how can programmatically perform native touch in specific point on screen?

within web view there html contains iframe, web view code , elements not accessible , sanding massages js not possible either. there button in web view on specific coordinates. how can press programmatically?

to simulate touch need write javascript function in web page can click button on behalf.

let's assume button on website loaded in iframe coded following:

<a href="#" id="magicbutton" onclick="targetfunction();">click me!</a> 

and iframe coded in webpage:

<iframe id="myiframe" src="http://www.stackoverflow.com" width="200" height="200"></iframe> 

in web page add following javascript function call click event on embedded button:

<script>     function myjavascriptfunction(){         //get handle 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 swift code, need use following api:

func evaluatejavascript(_ javascriptstring: string,       completionhandler completionhandler: ((anyobject?,                                  nserror?) -> void)?)  

you can execute javascript function calling following function after page has loaded:

   mywkwebview.evaluatejavascript("myjavascriptfunction(argument1, argument2);",                                                                completion:{ _ in }) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -