Results 1 to 1 of 1

Thread: Clicking on hyperlink after google search based on href value

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2017
    Posts
    3

    Clicking on hyperlink after google search based on href value

    hello,

    I have a macro that opens IE, navigates to google and conducts a search, but I'm stuck on how to click a certain link after the search is completed. Here is my code so far:
    __________________________________________________________

    'opening internet explorer'
    Dim ie As Object
    Set ie = CreateObject("internetexplorer.application")
    With ie
    .Visible = True
    .navigate "www.google.com"
    End With

    'Wait while IE loads'
    Do While ie.ReadyState = 4: DoEvents: Loop
    Do Until ie.ReadyState = 4: DoEvents: Loop

    'inputting search item'
    Var = "J.C Beaudin hockeydb"
    ie.document.getelementbyID("lst-ib").Value = Var

    'clicking search button'
    ie.document.forms(0).submit

    Do While ie.ReadyState = 4: DoEvents: Loop
    Do Until ie.ReadyState = 4: DoEvents: Loop

    __________________________________________________________


    looking at the element of the link I want to click, I get this:

    __________________________________________________________

    href="http://www.google.com/SearchTextHere'> Text of Hyperlink Displayed on Google
    __________________________________________________________

    Is there a way I can tell the macro to click on the hyperlink base on the href value or the text that follows it?
    I know that the first link that shows up will always be the first link that appears, based on my initial search text.

    Appreciate the help!!
    Cheers

    {{EDIT}}
    I figured it out!
    This is the code I used:

    ie.document.getElementsByTagName ("a")
    For Each l In ie.document.getElementsByTagName("a")
    If l.outerText = "website outertext" Then
    l.Click
    Exit For
    End If
    Next
    Last edited by vbabeginner90; May 22nd, 2017 at 09:16 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width