Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Sendkeys to ui.WebView
-
Trying to automate a webview by evaluating javascript in a page. I can set the input control value with a CSS selector, but the input control object triggers a validation event on the webpage and will not let me submit until the validation happens. The fastest way I can see to fix this is to send keys to the input control. I have tried this with javascript, but cannot send keys to the webview, just set the value of the control. Does anyone have any ideas on how to get this working?
-
IIRC, you have to change the specific element. Often you can do this without actually simulating keyevents, by setting the element value directly in javascript, using eval_js.
but if there is code that looks for keyevents, search stackoverflow for simulating keyevents in js. If the page has jquery loaded, it is a lot easier.
http://stackoverflow.com/questions/596481/simulate-javascript-key-eventsThere are browser security limitations which prohibit directly simulating key events. See Trevor's response above for a complete, if overkill, way to get close
-
Actually, if you know what the validation code is, you can call that function directly, or even easier, validation code often simply calls another submit function, so you could skip validation altogether and call the submit function directly.
It helps to look at the source code on a desktop pc with a developer console, to figure out the right calls to make with eval_js.
Another option, using eval_js gives you access to the DOM, and you can change the value of form elements, then click submit. Unless the validation depends on key events, this should also work.