C# 的cefsharp 里的ChromiumWebBrowser执行js
browserControl.ExecuteScriptAsync以这种方式执行js的时候报错,怎么解决...
browserControl.ExecuteScriptAsync以这种方式执行js的时候报错,怎么解决
展开
2个回答
展开全部
具体调用:
IBrowser browser = this._browser.GetBrowser();
if (browser.HasDocument)
{
IFrame mainFrame = browser.MainFrame;
var js = "var f= function A(){ return $('img',$('#"+id+"'));}; f();";
var task = mainFrame.EvaluateScriptAsync(js, null);// "(function() { var body = document.body, html = document.documentElement; return Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); })();", null);
//执行脚本
//browser.MainFrame.ExecuteJavaScriptAsync("document.getElementById('testid').click();");
//browser.MainFrame.ExecuteJavaScriptAsync("document.getElementById('testid2').value='123'");
task.ContinueWith(t =>
{
if (!t.IsFaulted)
{//返回结果
var response = t.Result;
var result = response.Success ? (response.Result ?? "null") : response.Message;
//html = result.ToString();
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}
IBrowser browser = this._browser.GetBrowser();
if (browser.HasDocument)
{
IFrame mainFrame = browser.MainFrame;
var js = "var f= function A(){ return $('img',$('#"+id+"'));}; f();";
var task = mainFrame.EvaluateScriptAsync(js, null);// "(function() { var body = document.body, html = document.documentElement; return Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); })();", null);
//执行脚本
//browser.MainFrame.ExecuteJavaScriptAsync("document.getElementById('testid').click();");
//browser.MainFrame.ExecuteJavaScriptAsync("document.getElementById('testid2').value='123'");
task.ContinueWith(t =>
{
if (!t.IsFaulted)
{//返回结果
var response = t.Result;
var result = response.Success ? (response.Result ?? "null") : response.Message;
//html = result.ToString();
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询