1
我試圖用awesomium登錄到https://accounts.google.com,但在單擊下一個按鈕後設置密碼字段時出錯。如何在C#中使用awesomium登錄谷歌帳戶.net
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Awesomium.Core;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var session = WebCore.CreateWebSession(new WebPreferences { WebSecurity = false });
using (WebView webViewBrowser = WebCore.CreateWebView(1024, 768, session, WebViewType.Offscreen))
{
webViewBrowser.ConsoleMessage += webViewBrowser_ConsoleMessage;
webViewBrowser.LoadingFrameComplete += webViewBrowser_LoadingFrameComplete;
webViewBrowser.Source = new Uri("http://www.blogger.com/");
if (WebCore.UpdateState == WebCoreUpdateState.NotUpdating) WebCore.Run();
Console.ReadKey();
}
}
static void webViewBrowser_ConsoleMessage(object sender, ConsoleMessageEventArgs e)
{
Debug.Print("{0} at {1}: {2} at '{3}'", e.EventName, e.LineNumber, e.Message, e.Source);
}
static void webViewBrowser_LoadingFrameComplete(object sender, FrameEventArgs e)
{
if (!e.IsMainFrame) return;
WebView webViewBrowser = sender as WebView;
Console.WriteLine(String.Format("Page Title: {0}", webViewBrowser.Title));
Console.WriteLine(String.Format("Loaded URL: {0}", webViewBrowser.Source));
dynamic Email = (JSObject)webViewBrowser.ExecuteJavascriptWithResult("document.getElementById('Email');");
Email["value"] = "[email protected]";
dynamic btn = (JSObject)webViewBrowser.ExecuteJavascriptWithResult("document.getElementById('next');");
btn.click();
dynamic Passwd = (JSObject)webViewBrowser.ExecuteJavascriptWithResult("document.getElementById('Passwd');");
Passwd["value"] = "pass007";
btn = (JSObject)webViewBrowser.ExecuteJavascriptWithResult("document.getElementById('signIn');");
btn.click();
BitmapSurface surface = (BitmapSurface)webViewBrowser.Surface;
surface.SaveToPNG("result.png", true);
WebCore.Shutdown();
}
}
}
上線的passwd [ 「值」] = 「pass007」 異常;:
'System.InvalidOperationException' 類型的異常出現在 Awesomium.Core.dll但在沒有處理用戶代碼
附加信息:不能對 無效(未定義)對象執行此操作。