c# WinForm 引用 Chrome 模拟操作
Nuget CefSharp.WinForms
public Form1() { InitializeComponent(); chromiumWebBrowser1.LoadingStateChanged += ChromiumWebBrowser1_LoadingStateChanged; } private void button1_Click(object sender, EventArgs e) { string url = "http://airadiov2.redefine.ltd/Login"; chromiumWebBrowser1.LoadUrl(url); } private void ChromiumWebBrowser1_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e) { this.BeginInvoke(new Action(() => { this.Text += e.IsLoading.ToString(); })); } private void button2_Click(object sender, EventArgs e) { var result = chromiumWebBrowser1.GetBrowser().MainFrame.GetSourceAsync(); //System.Threading.Thread.Sleep(10000); this.Text = result.Result; //browser.MainFrame.ExecutejavascriptAsync(); } private void button3_Click(object sender, EventArgs e) { chromiumWebBrowser1.GetBrowser().MainFrame.ExecuteJavaScriptAsync("document.getElementById('UserName').value='';"); chromiumWebBrowser1.GetBrowser().MainFrame.ExecuteJavaScriptAsync("document.getElementById('Password').value='';"); chromiumWebBrowser1.GetBrowser().MainFrame.ExecuteJavaScriptAsync("document.getElementById('bnt_login').click();"); var js = "function CheckObj(){ v = document.getElementById(\"UserName1\"); if(v==null){ return false; }else{ return true; }};; "; js += " CheckObj();"; var task = chromiumWebBrowser1.GetBrowser().MainFrame.EvaluateScriptAsync(js, null); task.ContinueWith(t => { if (!t.IsFaulted) { //返回结果 var response = t.Result; var result = t.Result.Success ? (response.Result ?? "null") : response.Message; MessageBox.Show(result.ToString()); } }, TaskScheduler.FromCurrentSynchronizationContext()); }