且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

单击包含 VBS 中某个字符串的链接

更新时间:2023-02-26 12:13:17

沿着线

Dim LinkHref昏暗LinkHref = "链接"对于每个 a 在 IE.Document.GetElementsByTagName("A")如果 LCase(a.GetAttribute("href")) = LCase(LinkHref) 那么a.点击Exit For ''# 在第一次点击后停止万一下一个

代替 LCase(…) = LCase(…),您还可以使用 StrComp(…, …, vbTextCompare)(参见 StrComp() 在 MSDN 上).>

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!

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