The code works only in half

 
Hostwinds

Results 1 to 7 of 7
Hei:) i'm finishing my program (sorry for newbie) but there is one problem.. The program ...
  1. #1
    Arjeen's Avatar
    Arjeen is offline Regular Member
    Join Date
    Aug 2012
    Location
    Verona (ITALY)
    Age
    22
    Posts
    265
    Thanks
    6
    Thanked 15 Times in 13 Posts

    Default The code works only in half

    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. #2
    Arjeen's Avatar
    Arjeen is offline Regular Member
    Join Date
    Aug 2012
    Location
    Verona (ITALY)
    Age
    22
    Posts
    265
    Thanks
    6
    Thanked 15 Times in 13 Posts

    Default Re: The code works only in half

    thanks for the help

  3. #3
    Psychop1 is offline Registered Member
    Join Date
    Jul 2010
    Posts
    61
    Thanks
    25
    Thanked 18 Times in 15 Posts

    Default Re: The code works only in half

    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. #4
    Arjeen's Avatar
    Arjeen is offline Regular Member
    Join Date
    Aug 2012
    Location
    Verona (ITALY)
    Age
    22
    Posts
    265
    Thanks
    6
    Thanked 15 Times in 13 Posts

    Default Re: The code works only in half

    this isn't the problem bro

  5. #5
    theMagicNumber is offline Regular Member
    Join Date
    May 2010
    Posts
    348
    Thanks
    160
    Thanked 182 Times in 110 Posts

    Default Re: The code works only in half

    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. #6
    Arjeen's Avatar
    Arjeen is offline Regular Member
    Join Date
    Aug 2012
    Location
    Verona (ITALY)
    Age
    22
    Posts
    265
    Thanks
    6
    Thanked 15 Times in 13 Posts

    Default Re: The code works only in half

    But mine are true or no? Becouse the first search is correct, and other no..

  7. #7
    Psychop1 is offline Registered Member
    Join Date
    Jul 2010
    Posts
    61
    Thanks
    25
    Thanked 18 Times in 15 Posts

    Default Re: The code works only in half

    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.

BlackHatWorld Advertising


★Guardians Of The Galaxy Network★ Super Homepage Links | No SERP Rise = 100% Refund!!!

Similar Threads

  1. redirect code that works for all browsers???
    By dombryan973 in forum BlackHat Lounge
    Replies: 0
    Last Post: 12-06-2010, 06:07 AM
  2. Replies: 7
    Last Post: 09-15-2010, 01:49 PM
  3. Coupon Code For Half Off Hosting
    By fbrcold in forum Black Hat SEO
    Replies: 3
    Last Post: 10-05-2009, 07:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


 



BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109