3

I'm able to navigate to gmail, but then I want to do something as simple as enter the credientials and click the login button.

private void btnSubmit_Click(object sender, EventArgs e)
{       
    btnSubmit.Enabled = false;        
    webGmail.LoadURL("http://www.gmail.com");

    webGmail.LoadCompleted += ExecuteSomething;
}

private void ExecuteSomething(object sender, EventArgs eventArgs)
{
    webGmail.ExecuteJavascript(@"<script src = 'http://code.jquery.com/jquery-latest.min.js' type = 'text/javascript'></script>");
    webGmail.ExecuteJavascript(@"$('#Email').val('foo');");
    webGmail.ExecuteJavascript(@"$('#Passwd').val('bar');");
    webGmail.ExecuteJavascript(@"$('#signIn').click();");
}

Nothing happens. I know using developer tools with Chrome that you cant modify anything on the page. But is there a way of filling in forms?

Are there any other better headless browsers? I actually need one that supports a web control that I can put into my form so that I can see what is going on. This is mandatory

PaulM
  • 3,281
  • 3
  • 28
  • 38

3 Answers3

2

The problem is that the script tag is not javascript - it's HTML - so executing it as javascript will just throw an error. To load a script with the ExecuteJavascript method, you'd need to create a script element in javascript and inject it into the page head.

See here for an example: http://www.kobashicomputing.com/injecting-jquery-into-awesomium

DrDeth
  • 337
  • 1
  • 7
1

I recently came across a similar problem. I tried cefsharp, awesomium, open-webkit-sharp, geckofx. The most advanced was, oddly enough, WebBrowser. It allows you to perform almost all activities directly with C#. For example, click on a submit button in C# you could only in WebBrowser. If you still want to use an alternative engine, I recommend the open-webkit-sharp - it is the most advanced of them (although it has the same problem with the click of buttons).

Alex Butenko
  • 3,664
  • 3
  • 35
  • 54
  • The problem with WebBrowser was that I couldn't get it to work with ajaxified sites that rendered on the fly. WebBrowser is fine for pages which are loaded on demand and then their content is in the DOM. – PaulM Jul 15 '12 at 23:44
  • In fact, it is possible to work with ajax (although this is a big problem that no implemented events related to ajax). You can get actual DOM at any time when necessary. By the way, you can add event handlers for any element. – Alex Butenko Jul 15 '12 at 23:51
0

WatiN has an Javascript implementation for Webkit, which Awesomium is based on, the source code is free and can be downloaded at their homepage. Good luck.

Maybe this question could help you too, calling Javascript from c# using awesomium.

Community
  • 1
  • 1
Iwan1993
  • 1,669
  • 2
  • 17
  • 25