在VB6的经典,我们可以这样做:
In VB6 classical, we could do:
Private Sub Form_Load()
WebBrowser1.Navigate2 "http://yourSite.com"
End Sub
Private Sub Command1_Click()
With Webbrowser1
.Document.All("fieldName").Value = "some value"
'click the button
.Document.All("fieldName").Click
End With
End Sub
但在VB.Net,我们得到的错误,没有值
属性,所以我尝试:
However in VB.Net, we get error that there is no Value
property, so I tried:
With wb
' fill From field
.Document.All("fieldName").SetAttribute("Value", strFrom)
' click the button now
.Document.All("fieldName").RaiseEvent("Click")
End With
但即使这样,产生一个错误:
But even that generates an error:
Object reference not set to an instance of an object.
在行:
.Document.All("fieldName").SetAttribute("Value", strFrom)
如何做同样的事情在VB.net?
How to do same thing in VB.net ?
我记得旧VB6的方式,如果你想调用在VB.Net code一个HTML元素的单击事件:
I remember the old VB6 way, if you want to invoke a HTML Element's click event in VB.Net code:
Private Function ClickSubmitButton()
Dim theButton As HtmlElement
Try
' Link the ID from the web form to the Button var
theButton = webbrowser1.Document.GetElementById("loginbutton")
' Now do the actual click.
theButton.InvokeMember("click")
Return True
Catch ex As Exception
Return False
End Try
End Function
通过设置属性,试图以此为例(把我的头顶部):
With setting attributes, try this as an example (off the top of my head):
Dim textArea = webBrowser1.Document.All("foo")
If textArea <> Nothing Then
textArea.InnerText = "This is a test"
End IF