单击VB.NET中的“浏览器”按钮

时间:2017-07-04 10:42:06

标签: vb.net

我创建了一个小应用程序,它接受表单中的输入并将其输入到网页上的表单中。但是,我无法找到一种方法来单击继续按钮。无论我尝试什么,它都会返回错误。这是我目前正在做的,但它返回了一个错误。

'Define Store variable
        Dim Store As String
        Store = Me.TextBox1.Text
        'Define IP Address variable
        Dim IPAddress As String
        IPAddress = Me.TextBox2.Text
        'Define Username variable
        Dim Username As String
        Username = Me.TextBox3.Text
        'Define Password variable
        Dim Password As String
        Password = Me.TextBox4.Text

        ' Open Store Specific URL 1
        Dim IE As Object 'Internet explorer object
        Dim objCollection1 As Object 'Variable used for cycling through different elements
        Dim objCollection2 As Object 'Variable used for cycling through different elements
        Dim objCollection3 As Object 'Variable used for cycling through different elements
        Dim objCollection4 As Object 'Variable used for cycling through different elements
        Dim objCollection5 As Object 'Variable used for cycling through different elements
        Dim objCollectionA As Object 'Variable used for cycling through different elements

        'Create IE Object
        IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
        IE.Navigate("http://" & IPAddress & ":8080/")

        Do While IE.Busy
            Application.DoEvents() 'This allows the site to load first
        Loop

        'Find the field you are looking for and store it into the objCollection variable
        objCollection1 = IE.document.getelementsbyname("txtDeviceName")
        objCollection2 = IE.document.getelementsbyname("txtName")
        objCollection3 = IE.document.getelementsbyname("txtUID")
        objCollection4 = IE.document.getelementsbyname("txtPWD")
        objCollection5 = IE.document.getelementsbyname("txtOrgID")
        objCollectionA = IE.document.getelementsbyname("imgReregister")

        'Call element, and set value equal to the data you have from your form
        objCollection1(0).Value = "Value1"
        objCollection2(0).Value = "Value2"
        objCollection3(0).Value = Username
        objCollection4(0).Value = Password
        objCollection5(0).Value = "Value3"

        objCollectionA.getElementById("imgReregister").click()

我得到的错误是:

************** Exception Text **************
System.MissingMemberException: Public member 'getElementById' on type 'DispHTMLElementCollection' not found.
   at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
   at WindowsApp1.Form1.Button1_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

我试图在HTML页面上点击的按钮看起来像这样

input name="imgReregister" title="Register" class="image" id="imgReregister" type="image" src="../images/next.gif"

0 个答案:

没有答案