How to execute JavaScript code after loading a page in webview?

I need to send data via JavaScript to webview. After the page loads, I need to get the value of a given field.

It's working, but I have to click the button again as soon as the page loads in the webviwer.


protected void onCreate(Bundle savedInstanceState) {



webView = (WebView) findViewById(;

textView1 = (EditText) findViewById(;

textView2 = (EditText) findViewById(;

textView3 = (TextView) findViewById(;

button = (Button) findViewById(;


WebSettings webSettings = webView.getSettings();


button.setOnClickListener(new View.OnClickListener() {


public void onClick(View view) {

String executaScript1 = "document.getElementById('campoLogin').value = 'admin';" +

"document.getElementById('campoSenha').value = 'admin';" +


String executaScript2 = "document.getElementById('disponivel').value;";

webView.loadUrl("JavaScript:" + executaScript1);

webView.evaluateJavascript("JavaScript:" + executaScript2, new ValueCallback() {


public void onReceiveValue(String...

Read More »

By: StackOverFlow - 6 days ago

Related Posts