如何在没有元素ID的情况下在vb Web浏览器中调用click事件? 你能救我吗?
答案 0 :(得分:3)
HtmlElement
对象中单击的HTML控件。您没有该ID,因此您无法使用GetElementById
,但还有许多其他内容可以帮助您获取您感兴趣的元素。请参阅下面的示例。InvokeMember
方法单击它。以下是一个例子:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim elements = WebBrowser1.Document.GetElementsByTagName("input") '' or whatever tag it is
For Each element As HtmlElement In elements
'' test here if this is the element of your interest.
'' e.g.
If element.GetAttribute("className") = "someclass" Then
element.InvokeMember("click") '' if found, click it!
Exit For
End If
Next
End Sub