tags:

views:

27

answers:

1

Hi! I'm trying to run an automated vbs script that clicks on a link on a page. I have things of the form:

Const READYSTATE_COMPLETE = 4  
Set IE = CreateObject("INTERNETEXPLORER.APPLICATION")  
IE.Visible = true  
IE.navigate ("http://mywebpage.com")

How do I then make it click on a link on that page that doesn't have an ID but is like

<a href="link">ClickMe!</a>

Thanks!

+2  A: 

Along the lines of

Dim LinkHref
Dim a

LinkHref = "link"

For Each a In IE.Document.GetElementsByTagName("A")
  If LCase(a.GetAttribute("href")) = LCase(LinkHref) Then
    a.Click
    Exit For  ''# to stop after the first hit
  End If
Next

Instead of LCase(…) = LCase(…) you could also use StrComp(…, …, vbTextCompare) (see StrComp() on the MSDN).

Tomalak