2012年9月18日 星期二

vbnet web 點擊 click


範例1:
HtmlElements elements = this.webBrowserControl.GetElementsByTagName("Input");

foreach(HtmlElement currentElement in elements)
{
currentElement.InvokeMember("click");
}

Dim elements As HtmlElements = Me.webBrowserControl.GetElementsByTagName("Input")
For Each currentElement As HtmlElement In elements
    currentElement.InvokeMember("click")
Next



範例2:
Me.WebBrowser1.Navigate(New Uri("http://www.yahoo.com"))

Me.ListBox1.Items.Add("Type" & "-->" & "Name")
For Each element As HtmlElement In Me.WebBrowser1.document.All
Me.ListBox1.Items.Add(element.TagName() & "-->" & element.Id)
Next


範例3:***本組ok***
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.WebBrowser1.Navigate(New Uri("http://www.yahoo.com"))
        Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("button")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("name").ToString
            controlName = "login"
                curElement.InvokeMember("click")
        Next
    End Sub


 範例4:good 引用 
Private Sub LogInSub()
        On Error GoTo err1
        WebBrowser1.Navigate(" webaddress")
        While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
            Application.DoEvents()
        End While
        Dim theElementCollection As HtmlElementCollection
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("id").ToString
            If controlName = "email" Then
                curElement.SetAttribute("Value", "username for site")
            End If
        Next
        theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("id").ToString
            If controlName = "password" Then
                curElement.SetAttribute("Value", "password for site")
            End If
        Next
        WebBrowser1.Document.Forms("login_pw").InvokeMember("submit")
err1:
        Exit Sub
    End Sub


沒有留言:

張貼留言