如何使用Web浏览器控件来填充HTML表单 [英] How to fill html form using web browser control

查看:204
本文介绍了如何使用Web浏览器控件来填充HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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

这篇关于如何使用Web浏览器控件来填充HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆