web.Execute()

761 views
Skip to first unread message

Timo Octazid

unread,
Apr 4, 2015, 4:44:11 PM4/4/15
to androi...@googlegroups.com
Hi,
I tried to work with web.Execute() to sign automatlicly in on a wepage loaded in my webview.
I want to fill out the login fields Username and password on the Droidscript wiki website. All I do gives me no result. Whats wrong? And how can I do this?
Here is my code. For the test I created a local webpage on my phone (to read the htmlcode).

function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
 
web = app.CreateWebView( 0.8, 0.8 );
lay.AddChild( web );
 
app.AddLayout( lay );
 
web.LoadUrl("file:///mnt/sdcard/Wikilogintest.htm");
web.Execute(Fillout);
}

function Fillout()
{
var test = document.getElementsByName("u");
test.value = "User";
}


Many Greetings
Timo
Message has been deleted
Message has been deleted

Steve Garman

unread,
Apr 4, 2015, 8:23:04 PM4/4/15
to androi...@googlegroups.com
Can't you just do something like this?

//(Sorry for the deleted posts. This is my third attempt.)

//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );    

    //Create a text label and add it to layout.
    var url = "http://wiki.droidscript.me.uk/doku.php?id=start&do=login"
    web = app.CreateWebView( .8,.8 );
    web.LoadUrl(url);
    lay.AddChild( web );

    btn=app.CreateButton("Execute");
    btn.SetOnTouch(exec);
    lay.AddChild(btn);
    
    //Add layout to app.    
    app.AddLayout( lay );
}

function exec()
{
    web.Execute('document.forms["dw__login"]["u"].value="user"')
    web.Execute('document.forms["dw__login"]["p"].value="mypassword"')
}


Steve Garman

unread,
Apr 4, 2015, 8:32:24 PM4/4/15
to androi...@googlegroups.com
And for the sake of completeness

function exec()
{
    web.Execute('document.forms["dw__login"]["u"].value="user"');
    web.Execute('document.forms["dw__login"]["p"].value="mypassword"');
    web.Execute('document.forms["dw__login"].submit()');
}

Timo Octazid

unread,
Apr 5, 2015, 3:33:17 AM4/5/15
to androi...@googlegroups.com
Hi
Thank you Steve, thats what I want. Some things for me are to easy to find them by myself :-)
I tried a long time but didnt find your easy solution.
One reason could be, that I didnt wait until the website is completly loaded. Thanks!

Many Greetings
Timo

Steve Garman

unread,
Apr 5, 2015, 2:46:17 PM4/5/15
to androi...@googlegroups.com
In case anyone is interested, the following code is hacked from a WebView I used before that needed a downloadComplete function.

I have altered it to fill in a very simple form at http://droidscript.sgarman.net/welcome.html


//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );    

    //Create a text label and add it to layout.
    var url = "http://droidscript.sgarman.net/welcome.html"
    web = createWebView( .8,.8 );
    web.SetOnProgress(progress)
    lay.AddChild( web );
    web.Load(url,"URL");
    
    //Add layout to app.    
    app.AddLayout( lay );
}

function progress(percent)
{
   if(percent==100) downloadComplete(this);
}

function downloadComplete(webview)
{
    if(webview.loadtype=="url")
    {
       //prevent looping
       webview.loadtype="";
       //sign in
       exec(webview);
    }
}

function exec(webview)
{
    webview.Execute('document.forms["myform"]["name"].value="Steve the Great"');
    webview.Execute('document.forms["myform"]["email"].value="st...@greatpeople.xxx"');
    webview.Execute('document.forms["myform"].submit()');
}

function createWebView(width, height)
{
    var w = app.CreateWebView(width,height);
    w.loadtype="";
    w.url="";
    w.html="";
    w.Load = function(data,type)
    {
      type = type||"url"
      type = type.toLowerCase();
      w.loadtype = type;
      if(type == "url")
      {
        w.url = data;
        w.LoadUrl(data);
      }
      if(type == "html")
      {
        w.html = data;
        w.LoadHtml(data);
      }
    }
    return w;
}

Steve Garman

unread,
Apr 5, 2015, 2:52:50 PM4/5/15
to androi...@googlegroups.com
I suppose the download complete function should have been

function downloadComplete(webview)
{
    if(webview.loadtype=="url")
    {
       //prevent looping
       webview.loadtype="";
       //sign in
       if(webview.url=="http://droidscript.sgarman.net/welcome.html")
       {
       exec(webview);
       }
    }
}

Rasmus "Termo" Lundsgaard

unread,
Jul 1, 2015, 3:13:54 AM7/1/15
to androi...@googlegroups.com
This is more or less exactly what I want to do. I got it up and running with login to my router at home, but the real script is to login to a specific computer where the textfields are implemented with Ember:

 <div class="controls"> {{view Ember.TextField valueBinding="userName"}} </div>

I have tried in different ways to set the field, but I'm not doing it correct apparently :(
Reply all
Reply to author
Forward
0 new messages