4

私はYahooの登録ページのフィールドを自動入力する小さなVB.NETプロジェクトで働いています。「チェック」ボタンをクリックして、入力したIDに問題がないか確認する方法はありますか?

入力したIDに問題がない場合は、フィールドへの入力を続行します。そうでない場合は、別のIDを試し、[チェック]ボタンをもう一度押します。

4

2 に答える 2

7

webbrowserコントロールを使用すると、Webページ内の要素にアクセスでき、それらの要素でメソッドを呼び出すことができるため、これと同じくらい簡単な方法でボタンをクリックします。

webBrowser1.Document.All("yidHelperBtn").InvokeMember("click");
于 2011-02-16T17:50:49.317 に答える
0

1000ミリ秒の間隔で、アプリケーションにタイマーを追加します。コードは次のとおりです。

Dim CheckButton, yahooId As HtmlElement
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _ 

WebBrowser1.DocumentCompletedを処理します

    yahooId = WebBrowser1.Document.GetElementById("yahooid")
    CheckButton = WebBrowser1.Document.GetElementById("yidHelperBtn")

    yahooId.InnerText = "testID" 'Replace testID by the ID you want

    Timer1.Start() 'Starts the timer: within 1000 ms (1 s). It will execute the Timer1_Tick sub.

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    CheckButton.Focus() 'Give the check button the focus
    SendKeys.Send("{ENTER}") 'Causes the validation of the check button
    Timer1.Stop() 'Stops the timer 
End Sub

WebBrowser1_DocumentCompletedメソッドを使用している間、ブラウザーがEnterキーを検証していないように見えるため、タイマーを追加しました。

このコードを使用すると、入力したIDがOKかどうかを知ることができます。完全ではありませんが、良い始まりです。理解して、ニーズに合わせて調整してください。

于 2011-02-16T16:33:38.427 に答える