如何以编程方式在 WebView 中输入表单输入字段,然后单击提交?
我在解析 WebView HTML 或加载 URL(相对或绝对)时没有任何问题,但我对如何以编程方式“模拟”用户输入用户名和地址感到困惑。密码,然后单击提交/登录按钮,给出以下 HTML:(
<form method="post" class="mobile-login-form" id="login_form" action="https://www.example.com/login.php?m=m&refsrc=http%3A%2F%2Fm.example.com%2F&refid=0">
<input type="hidden" name="lsd" autocomplete="off">
<input type="hidden" name="post_form_id" value="1b3cf017c90d483cc50fcac3f2a9a283">
<input type="hidden" name="charset_test" value="€,´,€,´,?,?,?">
<input type="hidden" name="version" value="1">
<input type="hidden" id="ajax" name="ajax" value="1">
<input type="hidden" id="width" name="width" value="313">
<input type="hidden" id="pxr" name="pxr" value="1.5">
<input type="hidden" id="gps" name="gps" value="1">
<div class="bgx msf" data-sigil="intfs">
<div class="mfss fcg">Username:
</div>
<input class="input mobile-login-field" name="username" value="" type="text">
</div>
<div class="bgx msf" data-sigil="intfs">
<div class="mfss fcg">Password:
</div>
<input class="input mobile-login-field" autocorrect="off" autocapitalize="off" name="pass" type="password">
</div>
<div class="bgx msf" data-sigil="intfs">
<label class="btn btnC touchable" data-sigil="blocking-touchable">
<input type="submit" value="Log In" class="mfss" name="login">
</label>
</div>
</form>
我不控制该 HTML,这只是任意网站提示的示例)
我不需要执行所谓的“静默身份验证” - 我只是想为用户提供一个方便的快捷方式,单击按钮而不是重新输入用户名和密码。一遍又一遍地输入密码(以防执行清除缓存
或清除数据
)。
I don't have any problem parsing WebView HTML or loading URLs (relative or absolute) but I am stumped as to how to programmatically "simulate" the user entering username & password, then clicking the submit/login button, given the following HTML:
<form method="post" class="mobile-login-form" id="login_form" action="https://www.example.com/login.php?m=m&refsrc=http%3A%2F%2Fm.example.com%2F&refid=0">
<input type="hidden" name="lsd" autocomplete="off">
<input type="hidden" name="post_form_id" value="1b3cf017c90d483cc50fcac3f2a9a283">
<input type="hidden" name="charset_test" value="€,´,€,´,?,?,?">
<input type="hidden" name="version" value="1">
<input type="hidden" id="ajax" name="ajax" value="1">
<input type="hidden" id="width" name="width" value="313">
<input type="hidden" id="pxr" name="pxr" value="1.5">
<input type="hidden" id="gps" name="gps" value="1">
<div class="bgx msf" data-sigil="intfs">
<div class="mfss fcg">Username:
</div>
<input class="input mobile-login-field" name="username" value="" type="text">
</div>
<div class="bgx msf" data-sigil="intfs">
<div class="mfss fcg">Password:
</div>
<input class="input mobile-login-field" autocorrect="off" autocapitalize="off" name="pass" type="password">
</div>
<div class="bgx msf" data-sigil="intfs">
<label class="btn btnC touchable" data-sigil="blocking-touchable">
<input type="submit" value="Log In" class="mfss" name="login">
</label>
</div>
</form>
(I don't control that HTML, this is just an example for an arbitrary website prompt)
I don't need to do so called "silent authentication" - I merely want to provide a convenience shortcut for the user clicking a button instead of re-typing username & password over and over again (in case, clear cache
or clear data
were performed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用猴子工具?应该可以完成这个任务。
Have you tried using monkey tools. Should be able to do that task.
在 html 页面中定义 JS 函数并使用以下方法调用它。
Define JS function within your html page and call it with following method.