title: Getting content out of WebView In a unit test Android, using java script
body: <p>I have been able to get content out of WebView using javascript and loadUrl() method having specified an interface thats called from javascript string that is injected into WebView.The problem is that this only works for me when the loadUrl() method is present in onPageFinished() method in the WebView client. What I want to do is I want to get the content out of the WebView (with the content already loaded). The WebView is in an activity instrumentation test case and I can for instance use findAll() method and that works fine. For some reason I can not use loadUrl() and get the desired behaviour (which is injecting javascript and getting content out of the WebView with a help of an interface). </p>
  
  <p>PLease help.</p>
  
  <p>Thanks </p>
  
  <p>Pawel</p>
  
  <p>EDIT:
  Just adding code to show what I am doing exactly:</p>
  
  <p>Yes I understand that but my problem is that I am trying to do it within a test case this way:</p>
  
  <pre><code>public void testWebView() throws Exception {
  
      solo.sleep(3000); // wait for views to load on the screen
      WebView a=null;
      ArrayList&lt;View&gt; views = solo.getCurrentViews(); // I am using solo object to get views for the screen currently loaded
      for(View s:views)
      {
          if (s instanceof WebView)
          {
              a = (WebView)s; // this is where I get my WebView
          }
      }
  
      Instrumentation inst = getInstrumentation();
  
      inst.runOnMainSync(new Runnable()
      {
          public void run()
          {
           int d =a.findAll("something"); // this method runs fine on the object and i get the desired result
  
           WebSettings settings = a.getSettings(); 
           settings.setJavaScriptEnabled(true);
  
           a.loadUrl("javascript:document.location = document.getElementById('google').getAttribute('href')"); // this javascript is never executed and that is my problem
  
          }
      });
  
  
  }    
  </code></pre>