如何自动点击网页视图里面的链接 [英] How to automate clicking a link inside a WebView

查看:478
本文介绍了如何自动点击网页视图里面的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,伙计们。我知道这听起​​来很奇怪,但我想要实现的是,当我运行应用程序。 web视图首先加载链接后,我进入所有的细节,它必须自动点击网页视图内的按钮。是否有任何可能的方式来做到这一点?我试图以便打开新窗口中加载不同的链接。

Ok, guys. I know it sounds weird but what I want to achieve is when i run the app. The webview first load the link and after I enter all the details, it must automatically click a button inside the webview. Is there any possible way to do this?? I have tried with loading different links in order to open the new window.

例如,

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    ourBrow = (WebView) findViewById(R.id.wvBrowser);
    // cancel the web intent that default in android setting
    ourBrow.setWebViewClient(new WebViewClient());
    url = (TextView) findViewById(R.id.tvSC);

    // webView settings
    ourBrow.getSettings().setJavaScriptEnabled(true);
    ourBrow.getSettings().setLoadWithOverviewMode(true);
    ourBrow.getSettings().setUseWideViewPort(true);
    Button SCode = (Button) findViewById(R.id.btSCode);
    loadUrl("http://www.google.com.au");

这部分工作得很好,但我想是当搜索栏里面的长度等于4,搜索按钮将自动preSS

this part works well, but what I want is when the length inside the search bar is equal to 4, the "search" button will automatically press

感谢这么多的帮助!

推荐答案

您可以也许在WebView中执行的一些尴尬的JavaScript做到这一点。

You could perhaps do this by executing some awkward javascript in the webview.

要刚刚发出点击你也许可以做类似

To just issue the click you could probably do something like

ourBrow.loadUrl("javascript:getElementById('button_id').click()");

因为你需要等待搜索栏有4 lenght你可能会想注册就在JavaScript领域的听众,并出具点击那里。我不能告诉你做到这一点的最好办法,但你可能会需要设置改变或设置的onkeyup或类似的EventListener,看看字段长度> = 4,则发出点击。你可以窝这一切的JavaScript排。

Since you need to wait for the search bar to have a lenght of 4 you will probably want to register a listener on the field in javascript and issue the click there. I can't tell you the best way to do this, but you will probably need to set an eventlistener for 'change' or set onKeyUp or something similar and see if the field is of length >= 4 then issue the click. You could nest all of this in the javascript row.

设置在页面加载后,即得。坐落在一个网页视图 WebViewClient ,并在<$ C加载JavaScript $ C> onPageFinished(的WebView视图,字符串URL)回调或类似的东西。

Set it after the page has loaded, that is. Set a WebViewClient on the webview and load the javascript in the onPageFinished(WebView view, String url) callback or something similar.

这篇关于如何自动点击网页视图里面的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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