Link Clicker

Discussion in 'Visual Basic .NET' started by Jixor, Feb 14, 2012.

  1. Jixor

    Jixor Registered Member

    Joined:
    Jan 1, 2012
    Messages:
    86
    Likes Received:
    7
    Hi

    Ok so I'm not the most experienced in this field but I'm trying to create a program that visits a page, finds a link and then clicks on it. This is what I have so far:

    Any help would be appreciated.

    PS Cant use GetElementbyID as there is no visible ID in page source.

    Code:
            If Web1.Visible Then
                For Each elem As HtmlElement In Web1.Document.GetElementsByTagName("a")
                    If elem.InnerText = "embedded link in href tag" Then
    
                        'Invoke("click")?
    
                        Exit For
                    End If
                Next
    
    
    
            End If
    
    
     
  2. Jixor

    Jixor Registered Member

    Joined:
    Jan 1, 2012
    Messages:
    86
    Likes Received:
    7
    No one can help?
     
  3. fr33dium

    fr33dium Registered Member

    Joined:
    Apr 30, 2010
    Messages:
    58
    Likes Received:
    11
    try this : elem.InvokeMember("click") It should works

    or if not working :
    elem.Focus()
    elem.InvokeMember("click")
     
    • Thanks Thanks x 1
  4. Jixor

    Jixor Registered Member

    Joined:
    Jan 1, 2012
    Messages:
    86
    Likes Received:
    7
    Ok I'll give this a try shortly. Thanks for your help.

    EDIT

    I got this working with some links but embedded objects seem to be a problem. Any idea how I could simulate a click on a embedded YouTube Video? I've tried using the above method but it doesn't seem to like it.

    Any suggestions?
     
    Last edited: Feb 15, 2012
  5. Skills

    Skills Newbie

    Joined:
    Aug 17, 2010
    Messages:
    46
    Likes Received:
    4
    Location:
    Carolina
    Try:
    For Each elem As HtmlElement In Web1.Document.GetElementsByTagName("img")

    System.IO.File.AppendAllText("img.txt",HtmlElement.src.tostring)

    Next

    or

    For Each elem As HtmlElement In Web1.Document.GetElementsByTagName("div")
    elem.Focus()
    elem.InvokeMember("click")
    Next
     
  6. Jixor

    Jixor Registered Member

    Joined:
    Jan 1, 2012
    Messages:
    86
    Likes Received:
    7
    Thanks for the reply. However in your second solution it would basically click through all DIV tags on the page. For example the page I'm on is a twitter page.

    Atthis point in time though I'm using a different method and now trying to get my webbrowser object to use an iphone useragent. However it does not like YT mobile one bit lol.
     
    Last edited: Feb 15, 2012
  7. andee

    andee Regular Member

    Joined:
    Jul 24, 2010
    Messages:
    218
    Likes Received:
    83
    its prob not the answer you want, but if ive ever got a simple bot, ie just clicking a link, I just use Imacros, takes all of about 5 seconds to make lol