vb.net - Vb.Net Element.InvokeMember (“click”)

标签 vb.net youtube browser webbrowser-control

我正在尝试使自动登录并在youtube上搜索某些关键字,登录并键入关键字的部分是有效的,但是在编写关键字以单击搜索后我无法这样做,这是我的代码:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        WebBrowser1.Navigate("https://accounts.google.com/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dsign_in_button%26hl%3Den_US%26next%3D%252F%26nomobiletemp%3D1&hl=en_US")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        Dim theElementCollection As HtmlElementCollection = 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", "email here")
            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 = "Passwd" Then
                curElement.SetAttribute("Value", "password here")
            End If
        Next


        theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection
            If curElement.GetAttribute("value").Equals("Sign in") Then
                curElement.InvokeMember("click")
                'Javascript has a click method for we need to invoke on the current submit button element.  
            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 = "masthead-search-term" Then
                curElement.SetAttribute("Value", "Keyword Here")

            End If
        Next



        For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("Search")
            'Depending on how the source code is formatted on the tag, you may also try Element.OuterHTML, Element.InnerText and Element.OuterText in the line below
            If Element.InnerHtml.Contains("class=""yt-uix-button-content""") Then
                Element.InvokeMember("click")
                Exit For
            End If
        Next Element

    End Sub
End Class

最佳答案

嘿,也许这可行:

theElementCollection = WebBrowser1.Document.GetElementsByTagName("button")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("id").ToString
            If controlName = "search-btn" Then
                curElement.InvokeMember("click")
            End If
        Next

关于vb.net - Vb.Net Element.InvokeMember (“click”),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15735252/

相关文章:

PowerShell 脚本自行打开浏览器

c# - F# 之于 IronPython/IronRuby 就像 C# 之于 VB.NET?

vb.net - 有没有办法向 ComboBox 添加可点击的图标?

java - 如何通过 Youtube Data Api V3 获取建议 channel ?

python-3.x - 如何从 Youtube Data API v3 获取最大搜索结果?

javascript - 将 HTML 内容添加到用户剪贴板的跨浏览器技术

jquery 测试 - 暂停 DOM?

python - 初学者网络 GIS 制图

mysql - 为什么我总是收到这个 mysql 错误?

iframe - 即使 showinfo=0,Youtube 嵌入也会显示不需要的顶栏