1

我正在从列表框中调用大量网页,当每个页面加载时,我想在计时器转到下一页之前向用户发送一条消息。该页面包含一个表单,该表单具有一个文本框和一个发送表单内容的按钮。下面是我的代码和我要提交的表单。

问题是,一旦计时器进入下一个网页,它就会将信息添加到文本框并单击按钮,但它会在加载下一页时在最后一分钟完成,而且还不够是时候提交表格了。我试过增加计时器的时间,但这没有用。有人可以指出我做错了什么吗?提前致谢!

我的代码:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    If counter > ListBox2.Items.Count - 1 Then
        WebBrowser1.Navigate("http://www.myserver.com/listofusers.aspx")
        counter = 0
        Timer1.Enabled = False
        Button1.Enabled = True
        Button1.Text = "Message the unmessaged"
        ListBox2.Items.Clear()
    Else


        Button1.Enabled = False
        Button1.Text = "Working... "
        WebBrowser1.Navigate(ListBox2.Items(counter))
        Dim theElementCollection = WebBrowser1.Document.GetElementsByTagName("textarea")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("className").ToString
            If controlName = "profile" Then
                curElement.SetAttribute("value", "Your password is due to expire in 10 days, please change it as soon as possible")
            End If
        Next


        Dim theElementCollection2 = WebBrowser1.Document.GetElementsByTagName("input")
        For Each curElement As HtmlElement In theElementCollection2
            If curElement.GetAttribute("className").Equals("button norm-green") Then
                curElement.InvokeMember("click")
            End If
        Next
    End If
    counter = counter + 1

End Sub

表格:

<form action="sendmessage.aspx" method="post" name="sendmessage">

                <div class="aligncenter">
                    <span class="headline txtBlue size16">Send a Quick Message!</span>
                    <input maxlength="40" name="subject" size="33" type="hidden" 
                        value="Important information" />
                    <textarea class="profile" name="message"></textarea><br />
                    <input type="submit" class="button norm-green" style="" value="Send Quick Msg" name="sendmessage" />
                </div>
            </form>
4

1 回答 1

0

我整理了我的问题。我将 for each webbrowser 语句放在 webbrowser1.documentcompleted() 控件中,并在其周围放置了 if timer1.enabled = true 语句。

于 2014-02-24T13:51:29.423 回答