Rio
Rio

Reputation: 14902

Clicking on a link that contains a certain string in VBS

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!

Upvotes: 1

Views: 11516

Answers (1)

Tomalak
Tomalak

Reputation: 338426

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).

Upvotes: 5

Related Questions