如何使用C#net中的awesomium登录google帐户?
我正在学习Awesomium,下面是我尝试登录的代码。我能够成功地在页面中设置登录和密码字段值,但无法提交登录表单,单击也不起作用。有人能帮我怎么登录吗如何使用C#net中的awesomium登录google帐户?,c#,awesomium,google-login,C#,Awesomium,Google Login,我正在学习Awesomium,下面是我尝试登录的代码。我能够成功地在页面中设置登录和密码字段值,但无法提交登录表单,单击也不起作用。有人能帮我怎么登录吗 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Awesomium.Core; namespace Awesom { class Prog
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Awesomium.Core;
namespace Awesom
{
class Program1
{
public static void Main(String[] args)
{
Console.WriteLine("Started....");
WebView wv = WebCore.CreateWebView(1024, 600);
wv.Source = new Uri("https://accounts.google.com");
wv.LoadingFrameComplete += (s, e) =>
{
if (!e.IsMainFrame)
return;
dynamic document = (JSObject) wv.ExecuteJavascriptWithResult("document");
using(document)
{
//Works
var tbox = document.getElementById("Email");
tbox.value = "XXXXXXXX@gmail.com";
//Works
var pbox = document.getElementById("Passwd");
pbox.value = "**********";
//Doesnt work
var lform = document.getElementById("gaia_loginform");
lform.submit();
//Doesnt work
var sbox = document.getElementById("signIn");
sbox.click();
}
BitmapSurface surface = (BitmapSurface)wv.Surface;
surface.SaveToPNG("result.png", true);
WebCore.Shutdown();
};
WebCore.Run();
}
}
}
结果图像:
它起作用了,你只是截图太早了。如果使用
,则需要说明第二帧导航。单击()
非常感谢。真棒的回答!
public static void Main(String[] args)
{
Console.WriteLine("Started....");
WebView wv = WebCore.CreateWebView(1024, 600);
wv.Source = new Uri("https://accounts.google.com/");
FrameEventHandler handler = null;
handler = (s, e) =>
{
if (e.IsMainFrame)
{
// we have finished loading main page,
// let's unhook ourselves
wv.LoadingFrameComplete -= handler;
LoginAndTakeScreenShot(wv);
}
};
wv.LoadingFrameComplete += handler;
WebCore.Run();
}
private static void LoginAndTakeScreenShot(WebView wv)
{
dynamic document = (JSObject)wv.ExecuteJavascriptWithResult("document");
using (document)
{
//Works
var tbox = document.getElementById("Email");
tbox.value = "XXXXXXXX@gmail.com";
//Works
var pbox = document.getElementById("Passwd");
pbox.value = "**********";
FrameEventHandler handler = null;
handler = (sender, args) =>
{
if (args.IsMainFrame)
{
wv.LoadingFrameComplete -= handler;
BitmapSurface surface = (BitmapSurface)wv.Surface;
surface.SaveToPNG("result.png", true);
WebCore.Shutdown();
}
};
wv.LoadingFrameComplete += handler;
var sbox = document.getElementById("signIn");
sbox.click();
}
}