如何登录到谷歌在C#.NET中使用awesomium帐户? [英] How to login to google accounts using awesomium in C#.net?

查看:783
本文介绍了如何登录到谷歌在C#.NET中使用awesomium帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习Awesomium和下面是在我试图登录到 https://accounts.google代码.COM 。我能够成功在页面设置的登录名和密码字段值,但无法提交登录表单,同样没有点击的作品。 ?谁能帮助我如何登录

I'm learning Awesomium and following is the code in which I'm trying to login to https://accounts.google.com. I'm successfully able to set the login and password field values in the page, but not able to submit the login form, neither does the click works. Can anyone help me how to login?

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



结果图片:

Result image:

推荐答案

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

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

这篇关于如何登录到谷歌在C#.NET中使用awesomium帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆