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 aaa(){ return false;}; aaa();"; 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()); }
标签:c#,chromiumWebBrowser1,private,Chrome,MainFrame,result,GetBrowser,var,WinForm From: https://www.cnblogs.com/liushunli/p/17587016.html