如何在没有元素 ID 的情况下在 vb Web 浏览器中调用单击事件? 你能帮我吗?
最佳答案
- 获取要在
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
关于vb.net - 在没有 ID 的 Web 浏览器中调用 Click 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10726380/