1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest Last month we upgraded BlackHatWorld.com to a new platform - . If you notice anything that requires attention please start a new thread here.
    Dismiss Notice

The code works only in half

Discussion in 'Visual Basic .NET' started by Arjeen, Mar 11, 2013.

  1. Arjeen

    Arjeen Regular Member

    Joined:
    Aug 22, 2012
    Messages:
    271
    Likes Received:
    16
    Location:
    Verona (ITALY)
    Hei:) i'm finishing my program (sorry for newbie) but there is one problem..
    The program have to search the sentence on the ListBox1 and put in the WebBrowser, search and do it again, again, again, again..
    But only for the first ListBox1.SelectItem work.. I don't know why..

    This is my video problem:

    http://www.youtube.com/watch?v=HUzvsq8Txq0


    And this is my code:
    Code:
     Private Sub ElectricButton2_Click(sender As Object, e As EventArgs) Handles ElectricButton2.Click        WebBrowser1.Navigate("https://www.blurum.it/Web/")
            Dim searchBox As HtmlElement = Nothing
            Dim searchButton As HtmlElement = Nothing
            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
            Dim keyword As String = ListBox1.SelectedItem
            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
        End Sub
    
    
    
    
    
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Timer1.Enabled = True
            WebBrowser1.Navigate("https://www.blurum.it/Web/")
            Dim searchBox As HtmlElement = Nothing
            Dim searchButton As HtmlElement = Nothing
            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
            Dim keyword As String = ListBox1.SelectedItem
            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
            Dim asd = ListBox1.Items(0)
            WebBrowser1.Document.GetElementsByTagName("input").OfType(Of HtmlElement)().FirstOrDefault(Function(p) p.GetAttribute("classname") = "search_bar_input").InnerText = (asd)
            ListBox1.Items.RemoveAt(0)
            Dim r as New Random
            Timer1.Interval = r.Next(30000, 60000)
            Timer1.Enabled = True
        End Sub
     
  2. Arjeen

    Arjeen Regular Member

    Joined:
    Aug 22, 2012
    Messages:
    271
    Likes Received:
    16
    Location:
    Verona (ITALY)
    thanks for the help
     
  3. Psychop1

    Psychop1 Registered Member

    Joined:
    Jul 30, 2010
    Messages:
    63
    Likes Received:
    19
    Variable 'keyword' only returns the currently selected item (which will probably just be the first item). A better way to do what you are trying to accomplish would be to create a queue, and load the queue with your selected values. Then use the queue to set 'Keyword'
     
  4. Arjeen

    Arjeen Regular Member

    Joined:
    Aug 22, 2012
    Messages:
    271
    Likes Received:
    16
    Location:
    Verona (ITALY)
    this isn't the problem bro
     
  5. theMagicNumber

    theMagicNumber Regular Member

    Joined:
    May 13, 2010
    Messages:
    345
    Likes Received:
    195
    You still didn't solve your problem ?
    Can't you see that there are two inputs ?
    Code:
    <div class="search_bar_style">
                        <input name="ctrl_SearchControl$txtSearch" type="text" maxlength="255" id="txtSearch" class="search_bar_input" style="display:none;">
                        <input name="ctrl_SearchControl$A2350807d-11cb-41de-ac2f-ed36857e9d30" type="text" value="test" maxlength="255" id="A2350807d-11cb-41de-ac2f-ed36857e9d30" class="search_bar_input">
                    </div>
    
    Set your keyword to both of them.
     
  6. Arjeen

    Arjeen Regular Member

    Joined:
    Aug 22, 2012
    Messages:
    271
    Likes Received:
    16
    Location:
    Verona (ITALY)
    But mine are true or no? Becouse the first search is correct, and other no..
     
  7. Psychop1

    Psychop1 Registered Member

    Joined:
    Jul 30, 2010
    Messages:
    63
    Likes Received:
    19
    The problem may be that using a timer to automate a webbrowser control is crossthreading. Try using the second part of your code in a document completed event. Could also be that you are using the selected item from a listbox to populate your 'keyword' variable, then removing that item from the listbox, possibly leaving no item selected. Use a loop or a queue to step through your keywords.