自动填写 webview 中的字段 [英] Fill fields in webview automatically

查看:31
本文介绍了自动填写 webview 中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上看到过这个问题,但我还没有找到可行的解决方案.基本上,我想加载我的应用程序并按下一个按钮;然后按钮操作将在已加载到 webview 的网站中填写用户名和密码(或等待 onPageFinished).最后,登录页面上的提交按钮将被激活.

I have seen this question floating around the internet, but I haven't found a working solution yet. Basically, I want to load my app and press a button; the button action will then fill in a username and password in a website already loaded in the webview (or wait for onPageFinished). Finally, the submit button on the login page will be activated.

据我所知,这可以通过使用 loadUrl(javascript) 进行 java 注入来完成,但我不知道用于填充字段的 java 命令是什么.对 iOS,但命令略有不同.

From what I understand this can be done by doing a java injection with the loadUrl(javascript), but I don't know what the java commands would be to fill in the fields. The same question was asked for iOS, but the commands are slightly different.

是否可以在 webivew 中使用 javascript 执行我要求的操作,或者我是否必须在没有像 this这个?

Is it possible to do what I am asking with javascript in a webivew, or do I have to do a http-post without a webview like this or this?

非常感谢您提供的任何帮助!

Thank you so much for any help you can give!

推荐答案

你不需要使用java命令"...而是JavaScript...例如:

You don't need to use "java commands"... but instead JavaScript... for instance:

String username = "cristian";
webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");

所以基本上,您需要做的是一大串 JavaScript 代码,它将获取这些字段并在其上放置值;此外,您还可以通过 JavaScript 启用/禁用提交按钮.

So basically, what you have to do is a big string of JavaScript code that will get those fields and put values on them; also, you can enable/disable the submit button from JavaScript.

这篇关于自动填写 webview 中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆