使用下面的代码,我登录了一个网站,然后在我需要获取图片中突出显示的文本框之后。但是,文本框没有 id。我如何才能进入文本框以自动输入信息。谷歌检查文本框元素
公共子 start_processing()
webBrowser1.Navigate("login to website passing credentials")
Do Until webBrowser1.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
webBrowser1.Navigate("https://secure.tmhp.com/TexMedConnect/EV/Default.aspx?pn=usercontrols/AcuteCare/EligibilityVerification")
Do Until webBrowser1.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
WebBrowser1.Document.GetElementById("fdosDatePicker").SetAttribute("Eligibility From Date", "11/22/2017")
'Also have been trying to get this to work but still cannot establish the input box
Dim allelements As HtmlElementCollection = webBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
If webpageelement.GetAttribute("class") = "igte_TMCEditInContainer igte_TMCEditInContianer" Then
MessageBox.Show("in if")
webpageelement.SetAttribute("value", "example")
End If
Next
end sub
或多或少你在做什么。
您可以解析 WebBrowser.Document 中的元素,然后将您关心的元素设置为新值。
在这里,我假设有 1 个或多个表单,它们有一个提交按钮。
这是标准。如果您的情况有所不同,则可以轻松调整。
Dim _found As Boolean = False
If webBrowser1.Document.Forms.Count > 0 Then
For Each _form As HtmlElement In _htmlpage.Forms
'Get all <input> elements in the current Form
Dim _inputs As HtmlElementCollection = _form.GetElementsByTagName("INPUT")
'Start from the last element of the collection
For x As Integer = _inputs.Count - 1 To 0 Step -1
'A submit element has been found, so look for the "wanted" element
If _inputs(x).GetAttribute("type") = "submit" Then
For Each _input As HtmlElement In _inputs
'When found, set its new value
If _input.GetAttribute("class") = "igte_TMCEditInContainer" Then
_input.SetAttribute("value", "example")
_found = True
Exit For
End If
Next
Exit For
End If
Next
If _found = True Then Exit For
Next
End If
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句