我正在使用的网页上有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存储以进行下一步
答案 0 :(得分:0)
也许尝试类似这样的事情,假设链接的Name
是“Letters”,并且假设前缀“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
,所以如果上述方法不起作用,请尝试稍微调整一下。