Ciao ragazzi, allora io ho creato un codice abbastanza che in pratica seleziona una parola nella ListBox e in automatico la inserisce in un text (ad esempio Google, che ovviamente è nel WebBrowser) e prema il pulsante "Cerca" da solo, fin qui tutto OK.
Funziona al 98% perché il programma effettivamente in automatico seleziona la parola dalla ListBox e cerca (ad es. su Google), il problema sta che nella "text box" di google non compare scritto nulla, ma cerca solamente.. Io vorrei vedere la parola selezionata dalla ListBox..
E' un piccolo difetto che non riesco a risolvere.. Vi lascio il mio codice:
codice:
Private Sub ElectricButton2_Click(sender As Object, e As EventArgs) Handles ElectricButton2.Click
Dim searchBox As HtmlElement = Nothing
Dim searchButton As HtmlElement = Nothing
Dim keyword As String = ListBox1.SelectedItem
searchBox = WebBrowser1.Document.GetElementsByTagName("input").OfType(Of HtmlElement)().FirstOrDefault(Function(p) p.GetAttribute("classname") = "search_bar_input")
searchButton = WebBrowser1.Document.GetElementsByTagName("input").OfType(Of HtmlElement)().FirstOrDefault(Function(p) p.GetAttribute("classname") = "search")
Do While WebBrowser1.Document Is Nothing OrElse searchBox Is Nothing OrElse searchButton Is Nothing
Application.DoEvents()
searchBox = WebBrowser1.Document.GetElementsByTagName("input").OfType(Of HtmlElement)().FirstOrDefault(Function(p) p.GetAttribute("classname") = "search_bar_input")
searchButton = WebBrowser1.Document.GetElementsByTagName("input").OfType(Of HtmlElement)().FirstOrDefault(Function(p) p.GetAttribute("classname") = "search")
Loop
WebBrowser1.Document.GetElementsByTagName("input").OfType(Of HtmlElement)().FirstOrDefault(Function(p) p.GetAttribute("classname") = "search_bar_input").InnerText = (keyword)
searchBox.SetAttribute("value", keyword)
searchButton.InvokeMember("click")
WebBrowser1.Refresh()
For i As Integer = ListBox1.SelectedItems.Count - 1 To 0 Step -1
Dim k As Integer = ListBox1.SelectedIndices(i)
ListBox1.Items.RemoveAt(k)
Next
Timer1.Enabled = True
Lo so che potevo fare tutto comodamente con
codice:
Dim asd = ListBox1.SelectedItem
WebBrowser1.Document.GetElementById("txtSearch").InnerText = (asd)
Ma io voglio quello mio..
Grazie per le risposte!