0

我正在使用的网页上有 60 到 100 个菜单链接,具体取决于用户凭据。我使用此代码单击菜单链接:

 Set oapp = CreateObject("Shell.Application")
         For i = 0 To 25
         StrName = ""
         On Error Resume Next
         StrName = oapp.Windows(i).Document.URL
         If InStr(StrName, "mywebaddress.aspx") Then
         Set oie = oapp.Windows(i)
         Exit For
         End If
         Next
         oie.Document.all("ctl11_repeaterNavigator_ctl32_menuLink").Click

但链接号会根据用户凭据而变化 - 我的凭据 _ctl32 在其他人身上可以是 _ctl32 或 _ctl33。有没有办法搜索内部文本并将链接 ID 存储为字符串?

I know I can click on the link by using:
For i = 1 To oie.Document.all.Length
 If oie.Document.all.Item(i).innerText = "Letters" Then
 oie.Document.all.Item(i).Click
 Exit For
End If
Next i

但我需要将链接 ID 存储在字符串中以供下一步

4

1 回答 1

0

也许尝试这样的事情,假设链接Name是“字母”并且假设前缀“ctl11_repeaterNavigator_”和足够的“_menuLink”不会为用户改变。

Dim ele as Variant
Dim parseString as String

'## Determine what ctl to use:'

For each ele in oie.Document.GetElementsByName("Letters") '## Modify to use the Name associated with this menu link '
    If Right(ele.InnerHTML,9) = "_menuLink" AND _
        Left(ele.InnerHTML, 24) = "ctl11_repeaterNavigator_" Then 
        ele.Click
        Exit For
    End If
Next

如果上述方法不起作用,可能必须使用ele.InnerText而不是,请尝试稍微调整一下。.InnerHTML

于 2013-04-30T18:41:52.730 回答