自動ログインを作成して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