填写的WebView在线表格文本字段没有ID的 [英] Fill text fields in WebView online form without id's

查看:109
本文介绍了填写的WebView在线表格文本字段没有ID的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着做一个程序使用本地字符串变量来填写一份在线登录。
以下是我迄今为止:

Im trying to make a program to fill out an online login using local string variables. Here is what i have so far:

        web = (WebView) findViewById(R.id.webview);
        WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        web.getSettings().setUserAgentString("Mozilla/5.0 " +
                "(Windows NT 6.2; " +
                "WOW64) AppleWebKit/537.31 " +
                "(KHTML, like Gecko) Chrome/20 " +
                "Safari/537.31");
        web.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
        web.loadUrl("http://ta.yrdsb.ca/yrdsb/");

        web.setWebViewClient(new WebViewClient() {
           public void onPageFinished(WebView view, String url) {
              String username="test";
              String password="test";
              view.loadUrl("javascript:document.getElementById('username').value = '"+username+"';document.getElementById('password').value='"+password+"';");
           }
        });

我的问题是,该领域不被填充。我认为这个问题是ID的,因为从我所看到的,似乎在这个特定网站的文本字段没有与之相关的ID。这是username字段(没有ID):

My problem is that the fields are not being filled in. I think the issue is with the id's, because from what i can see, it seems that the text fields on this particular site do not have an id associated with them. This is what the username field is (there is no id):

<input type="text" name="username" size="10" border="0">

所以我的问题是如何将我去这样做,而无需用户名和密码字段的ID,还是我只是失去了一些东西?

So my question is how would i go about doing this without having the ids of the username and password fields, or am i just missing something?

先谢谢了。

推荐答案

如果你没有任何的ID,你可以这样做:

If you dont have any ID's you can do this:

document.getElementsByName("username")[0].value = "username";

您目前由ID requresting但is'nt元素上的任何标识。

You are currently requresting by ID but there is'nt any ID on the element.

这篇关于填写的WebView在线表格文本字段没有ID的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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