VB.NET Webbrowser,htmlelement 通过没有 ID 的元素获取文本框
VB.NET Webbrowser, htmlelement getting a textbox by element that has no ID
使用下面的代码我登录到一个网站,然后我需要获取图片中突出显示的文本框。但是,文本框框没有 id。我怎样才能进入文本框以自动输入信息。Google Inspection of the textbox element
Public 子 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
使用下面的代码我登录到一个网站,然后我需要获取图片中突出显示的文本框。但是,文本框框没有 id。我怎样才能进入文本框以自动输入信息。Google Inspection of the textbox element
Public 子 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