从VB.NET中单击浏览器按钮
我创建了一个小应用程序,它接受表单中的输入并将其输入到网页上的表单中。但是,我无法找到单击“继续”按钮的方法。无论我尝试什么,它都会返回一个错误。这是我目前正在做的,但它返回了一个错误从VB.NET中单击浏览器按钮,vb.net,Vb.net,我创建了一个小应用程序,它接受表单中的输入并将其输入到网页上的表单中。但是,我无法找到单击“继续”按钮的方法。无论我尝试什么,它都会返回一个错误。这是我目前正在做的,但它返回了一个错误 'Define Store variable Dim Store As String Store = Me.TextBox1.Text 'Define IP Address variable Dim IPAddress As String
'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"
为什么人们一直在使用
Application.DoEvents()
,他们从哪里得到的?!这是非常糟糕的做法!改为添加对Microsoft Internet控件的引用,并订阅。请参阅:关于您的问题:您只能在文档上调用getElementById
,而不能在集合上调用。可能您可以通过objCollectionA(“imgReregister”)
通过其id访问元素,否则您只需检查Microsoft Internet Controls
的可用方法。实际上,我忘了我有一个答案,可以在添加对Microsoft Internet Controls
的引用时为您提供指导,这里: