开发者

Clicking on a link that contains a certain string in VBS

开发者 https://www.devze.com 2022-12-12 06:08 出处:网络
I\'m trying to run an automated vbs script that clicks on a link on a page. I have things of the form:

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!开发者_如何学JAVA</a>

Thanks!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消