3

Hello I want to know that is there any way to get value from webview html element or not. I did load page in webview as follows

package example.samplewebview; 

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.os.Bundle; 
import android.webkit.WebView; 

public class MainActivity extends Activity {
    WebView wv;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        wv = (WebView) findViewById(R.id.webView1);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.loadUrl("http://www.google.com");
        wv.get
    }
} 

and with this google.com page is loaded in webview. now i want to get value from that search textbox and store in database any help will be appreciate.

stealthjong
  • 10,858
  • 13
  • 45
  • 84
Nisarg Desai
  • 361
  • 3
  • 16
  • Take a look at Selendroid. I reckon that'll be able to do it. – stealthjong Aug 29 '14 at 14:24
  • As Far as My knowledge on Selenadroid its an testing framework.may you please provide some more specification. about how it can be used. – Nisarg Desai Aug 30 '14 at 04:13
  • I do not know exactly how Selendroid works (I work only with selenium), but though it's often used for testing purposes, it gives the possibility to interact with a browser, including extracting information from a website. On selendroids site, it states it can interact with Androids WebView as well. Which means it should be suitable for your needs. Just Google selendroid. I think it should work. – stealthjong Aug 30 '14 at 12:49
  • thanks man,i did google for it, and there is one webdriver class in api but they have not provide documentation for it. so its seems ver hard to implement it. Anyway Thanks for your help. – Nisarg Desai Sep 01 '14 at 03:28

1 Answers1

2

Assuming you are not Google, but you do want to use your own website, which you can modify, I suggest that you place a javascript on your webpage, that calls a native method inside your Android app and just submitts the value from this textfield.

There is already a thread on that topic here: android - get Text out of webview

Community
  • 1
  • 1
sschrass
  • 7,014
  • 6
  • 43
  • 62
  • Actually i already read this thread but submits the value to web server. I want that value at backend in java's activity extended class – Nisarg Desai Aug 30 '14 at 04:07
  • the first answer passes data to the native android layer if the page has loaded. You may want to pass data to the android layer if the user presses a button or similar. Till that point the answer points you in the right direction. – sschrass Aug 30 '14 at 08:21
  • view.loadUrl("javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);"); in this load url has void type so i cant do string s=view.loadUrl("javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);"); if that textbox value is lying on android layer then how can i store in variable of android (java) – Nisarg Desai Sep 01 '14 at 02:55
  • Thanks for link,i will try to figure out. – Nisarg Desai Sep 01 '14 at 08:10