簡體   English   中英

VB.NET在文本框中輸入文本,然后按發送Web瀏覽器

[英]VB.NET enter text on textbox and press send webbrowser

我正在從列表框中調用大量網頁,當每個頁面加載時,我想在計時器轉到下一頁之前向用戶發送一條消息。 該頁面包含一個表單,該表單具有一個文本框和一個發送表單內容的按鈕。 以下是我的代碼和我要提交的表單。

問題在於,計時器一旦轉到下一個網頁,就會將信息添加到文本框中並單擊按鈕,但是它在加載下一頁時的最后一刻才完成,而且還不夠是時候提交表格了。 我已經嘗試增加計時器的時間,但這沒有用。 有人可以指出我做錯了嗎? 提前致謝!

我的代碼:

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>

我整理了我的問題。 我在webbrowser1.documentcompleted()控件中放置了每個webbrowser語句,並在其周圍放置了if timer1.enabled = true語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM