我试图在Visual Studio 2012(Visual Basic)中使用WebBrowser单击按钮.我做了很多研究,但我能找到的只是点击ID或名称.
这是HTML代码.
<button type='submit' class="btn btn-default" style='float:right'> Login<i class="gicon-chevron-right"></i>
您需要逐个搜索您的元素.尝试这样的事情:
原文链接:https://www.f2er.com/vb/255879.htmlFor Each elem As HtmlElement In wb1.Document.GetElementsByTagName("button") ' Check the attributtes you want If elem.GetAttribute("class") = "btn btn-default" Then 'Check even the text if you want If elem.InnerText = "Login" Then 'Invoke your event elem.InvokeMember("click") End If End If Next
这将搜索文档上的所有按钮元素.您可以通过查看包含具有ID或其他内容的按钮的元素来缩小搜索范围:
Dim myElem As HtmlElement = wb1.Document.GetElementById("myContainerId") For Each elem As HtmlElement In myElem.GetElementsByTagName("button") '... Next