使用下面的代码我登录到一个网站,然后我需要获得图片中突出显示的文本框。但是,文本框没有id。我怎样才能进入文本框以自动输入信息。Google Inspection of the textbox element
Public Sub 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
答案 0 :(得分:0)
或多或少你在做什么。
您可以解析WebBrowser.Document中的元素,然后进行设置
那些你关心的新价值。
这里我假设有一个或多个表单,其中有一个提交按钮 这是标准。如果在你的情况下它有些不同,它很容易调整。
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