且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何登录到谷歌在C#.NET中使用awesomium帐户?

更新时间:2023-09-10 20:11:28

这是工作,你只是采取截图为时尚早。您需要考虑的第二个框架导航,如果你使用。点击()

It IS working, you're just taking the screenshot too early. You need to account for the second frame navigation, if you use .click().

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();
    }
}