我添加了Microsoft.mshtml作为对我的项目的引用,并完成了以下工作:
mshtml.IHTMLDocument2 document = (mshtml.IHTMLDocument2)webbrowser.Document;
string username = document.all["username"].GetAttribute("value");但是第二线不能用。上面写着
错误CS0021:不能将[]索引应用于‘mshtml.IHTMLElementCollection’类型的表达式
在“全部”上空盘旋时。我如何访问所有元素?
发布于 2013-04-05 14:01:09
试试这个:
var document = (IHTMLDocument3) webbrowser.Document;
var value =
document.getElementsByName("username")
.OfType<IHTMLElement>()
.Select(element => element.getAttribute("value"))
.FirstOrDefault();发布于 2016-12-15 07:17:43
在挣扎了几个小时之后,这个解决方案对我起了作用。
Dim document = DirectCast(MainBrowser.Document, IHTMLDocument3)
Dim formName = document.getElementsByName(AppSettings("myFormName")).OfType(Of IHTMLElement)().Select(Function(element) element.getAttribute("name")).FirstOrDefault()https://stackoverflow.com/questions/15835533
复制相似问题