填写表格以编程的Andr​​oid网页视图 - 的JavaScript [英] fill form programmatically in Android Webview - JavaScript

查看:169
本文介绍了填写表格以编程的Andr​​oid网页视图 - 的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的学校的网站上自动填写表单。
我见过一些方面做的javascrip。

I'm trying to automatically fill a form from the website of my school. I've seen some ways to do with javascrip.

下面是我的code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.navegador_siiau_layout);

    navegador_siiau = (WebView) findViewById(R.id.wv_navegador_siiau);
    navegador_siiau.getSettings().setJavaScriptEnabled(true);
    navegador_siiau.loadUrl("http://siiauescolar.siiau.udg.mx/wus/gupprincipal.inicio");
    navegador_siiau.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            String user="207512134";
            String pwd="FENMAA";
            view.loadUrl("javascript:document.getElementsByName('p_codigo_c').value = '"+user+"';document.getElementsByName('p_clave_c').value='"+pwd+"';");
        }
    });



}

其结果是最后一个字符串我试图把在形式的空白页...
我能做些什么,以正确填写并提交表格?

The result is a blank page with the last string I try to put in the form... What can I do to fill and submit the form correctly?

推荐答案

这是未经测试,但我错在这里看到两件事情:

This is untested, but I see two things wrong here:


  1. 您应该叫 setWebViewClient WebViewClient 实施你打电话之前使用loadURL 。然而,使用loadURL 是异步的,所以它可能不会有所作为,但是这是值得一试的,我认为。

  1. You should call setWebViewClient with your WebViewClient implementation before you call loadUrl. However, loadUrl is asynchronous, so it probably would not make a difference, but this is worth a try I think.

您不是叫 super.onPageFinished(查看URL); 在onPageFinshed。你应该添加此调用。

You are not calling super.onPageFinished(view, url); in onPageFinshed. You should add this call.

编辑2:

我最后看了一眼正在使用实际的页面。问题是,页面加载在不同框架中的内容,所以你确实有让 getElementsByName 呼吁其他文档。其中的两个输入你想要的位置的框架在你的页面的名称的mainFrame 。所以,你应该写的JavaScript像这样那样装入的WebView ,你在上面所做的:

I finally took a look at the actual page you are working with. The problem is that the page loads content in a different frame, so you actually have to make the getElementsByName call on a different document. The frame in which both of the inputs you want are located has the name mainFrame in your page. So, you should write the javascript like this and load that into the WebView as you have done above:

window.frames["mainFrame"].document.
                 getElementsByName('p_codigo_c')[0].value = "user";
window.frames["mainFrame"].document.
                 getElementsByName('p_clave_c')[0].value = "password";

这篇关于填写表格以编程的Andr​​oid网页视图 - 的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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