【发布时间】:2021-05-04 17:53:00
【问题描述】:
我正在尝试在我为实验创建的页面上提取特定的标签值。我是使用 Cefsharp 的新手。我正在尝试改进自己。我在 EvaluateScriptAsync 部分卡了大约两天。
我正在尝试捕获我准备的页面上特定标签中按钮的值。我通过按一个按钮运行以下代码。我的页面有3个具有相同标签的按钮。但是,它只打印其中之一。
<input type="button" id ="button1" value="First Button">
<input type="button" id ="button2" value="Second Button">
<input type="button" id ="button3" value="Third Button">
这些是我试图找到的按钮。
string script = @"(function() { " +
"var button = document.querySelectorAll('input[type = \"button\"]'); " +
"if(button != null) {for (var i = 0; i < button.length; i++) { return button[i].value;
}}else{alert('not found!');}" +
"})();";
chrome.EvaluateScriptAsync(script).ContinueWith(a =>{
var response = a.Result;
if (response.Success && response.Result != null)
{
string print = (string)response.Result;
MessageBox.Show(print.ToString());
}
}, TaskScheduler.FromCurrentSynchronizationContext());
我尝试了很多。我认为我在 javascript 部分犯了一个错误。我已经阅读了大多数类似的主题。但我找不到解决方案。
output : First Button
【问题讨论】:
标签: c# visual-studio winforms cefsharp