我试图使用VB.NET在我的用户表单上使用组合框从webbrowser控件中的组合框中选择一个下拉项。在过去的几天里,我一直在研究这个问题,并尝试了迄今为止我能找到的所有解决方案,但无济于事。
以下是我在网页浏览器控件中加载的HTML页面的片段,我称之为" screenerwebbrowser":
<select name="ctl00$bodyPlaceHolder$UniverseList" id="ctl00_bodyPlaceHolder_UniverseList" onchange="SBT.Util.Window.reload({UniverseID:this.value, PageViewID:this.value}, true);">
<option selected="selected" value="FOUSA">Mutual Fund</option>
<option value="STUSA">Stock</option>
<option value="FCUSA">Closed-end Fund</option>
<option value="FEUSA">Exchange Traded Fund</option>
<option value="VAFTUSA">First Trust VA Subaccount</option>
<option value="FIUSA">First Trust Unit Investment Trust</option>
</select>
&#13;
userform有一个名为ScreenerCheckBox的按钮,它使得名为ScreenerWebBrowser的webbrowser控件可见,并使用我试图控制的组合框加载网站。以下是我认为与此问题相关的代码:
Private Sub ScreenerCheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles ScreenerCheckBox.CheckedChanged
On Error Resume Next
Dim Website As String = "https://www.ftportfolios.com/Broker/SalesTools/Morningstar/MorningstarToolsMain.aspx"
Dim UserID As String = "Username"
Dim Pword As String = "Password"
If ScreenerCheckBox.Checked = True Then
ScreenerWebBrowser.Visible = True
With ScreenerWebBrowser
.Navigate(Website)
End With
holdScreenBrowser()
Timer1.Stop()
Dim UserNameTextBox As HtmlElement = ScreenerWebBrowser.Document.All.Item("ContentPlaceHolder1_Login1_txtLoginName")
Dim PasswordTextBox As HtmlElement = ScreenerWebBrowser.Document.All.Item("ContentPlaceHolder1_Login1_txtPassword")
UserNameTextBox.InnerText = UserID
PasswordTextBox.InnerText = Pword
ScreenerWebBrowser.Document.GetElementById("ContentPlaceHolder1_Login1_btnLogin").InvokeMember("click")
WaitForScreenLoad()
Timer1.Stop()
ScreenerWebBrowser.Document.GetElementById("ContentPlaceHolder1_btnAccept").InvokeMember("click")
WaitForScreenLoad()
Timer1.Stop()
ScreenerWebBrowser.DocumentText = IO.File.ReadAllText("https://www.ftportfolios.com/Broker/SalesTools/Morningstar/MorningstarToolsMain.aspx")
Else
With ScreenerWebBrowser
.Visible = False
.Navigate("about:blank")
.Refresh()
End With
End If
End Sub
Private Sub ScreenerWebBrowser_ProgressChanged(sender As Object, e As WebBrowserProgressChangedEventArgs) Handles ScreenerWebBrowser.ProgressChanged
On Error Resume Next
If e.CurrentProgress = -1 Then
Me.ProgressBar1.Value = 100
End If
If e.CurrentProgress > 0 And e.MaximumProgress > 0 Then
Me.ProgressBar1.Value = e.CurrentProgress / e.MaximumProgress
End If
End Sub
Public Sub holdScreenBrowser()
On Error Resume Next
Timer1.Enabled = True
sec2 = 0
Timer1.Start()
Do While ScreenerWebBrowser.IsBusy Or ScreenerWebBrowser.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
If sec2 >= 15 Then
Timer1.Stop()
ScreenerWebBrowser.Navigate("about:blank")
ScreenerWebBrowser.Refresh()
MsgBox("Sorry, the Application had some trouble loading the screener. This can be caused by an interruption in the internet connection or a problem with the web server. Please try again after a few minutes.", vbExclamation)
Exit Sub
End If
End Sub
Private Property ScreenerReady As Boolean = False
Public Sub WaitForScreenLoad()
Timer1.Enabled = True
Timer1.Start()
AddHandler ScreenerWebBrowser.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
While Not ScreenerReady
Application.DoEvents()
If sec2 >= 15 Then
Form6.Hide()
Timer1.Stop()
ScreenerWebBrowser.Navigate("about:blank")
ScreenerWebBrowser.Refresh()
MsgBox("Sorry, the Application had some trouble loading the screener. This can be caused by an interruption in the internet connection or a problem with the web server. Please try again after a few minutes.", vbExclamation)
Exit Sub
End If
End While
ScreenerReady = False
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If ScreenerWebBrowser.ReadyState = WebBrowserReadyState.Complete Then
ScreenerReady = True
RemoveHandler ScreenerWebBrowser.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End If
End Sub
以上代码将加载网站,登录&amp;接受条款,但我的组合框不会选择网站组合框中的任何选项。任何帮助将不胜感激!