VB.NET在文本框中输入文本,然后按发送webbrowser

时间:2014-02-23 20:43:27

标签: vb.net forms timer getattribute

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

问题是,一旦计时器进入下一个网页,它就会将信息添加到文本框并单击按钮,但它会在最后一刻完成,就像它正在加载下一页一样,并且没有没有足够的时间提交表格。我已经尝试增加计时器的时间,但这没有用。有人可以指出我做错了吗?提前谢谢!

我的代码:

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>

1 个答案:

答案 0 :(得分:0)

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