2

VB6クラシックでは、次のことができます。

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では、プロパティがないというエラーが発生するValueため、次のことを試しました。

  With wb
     ' fill From field
     .Document.All("fieldName").SetAttribute("Value", strFrom)
     ' click the button now
     .Document.All("fieldName").RaiseEvent("Click")
  End With

しかし、それでもエラーが発生します。

Object reference not set to an instance of an object.

オンライン:

.Document.All("fieldName").SetAttribute("Value", strFrom)

VB.netで同じことを行う方法は?

4

1 に答える 1

1

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
于 2012-05-27T05:51:35.180 に答える