提问人:Jack Jan 提问时间:7/5/2023 最后编辑:Jack Jan 更新时间:7/5/2023 访问量:56
使用 Excel vba 浏览网站的 IE 和菜单
Using Excel vba to navigate through IE and menus of the site
问:
在此处输入图像描述我是一个新手,试图通过Excel vba自动执行一些常规程序。但是我无法访问要单击的 HTML 元素。我想点击标题为“Prize Bonds”的菜单,然后点击它打开的子菜单之一。我试图通过标签、标签名、css 访问它,但没有任何效果。该错误不是由于找到元素造成的。我使用等待来加载网站,这样元素的存在就不是问题了。我的代码没有给出任何错误,但它也不会单击所述菜单。我正在上传图像以显示 DOM 并找到 HTML 元素。代码是
Sub auto_ie()
Dim IE As New SHDocVw.InternetExplorer
Dim usrname As Variant
Dim pass As Variant
Dim MSDOC As MSHTML.HTMLDocument
Dim inputs As MSHTML.IHTMLElement
Dim passwords As MSHTML.IHTMLElement
Dim singin As MSHTML.IHTMLElement
Dim Anchors As MSHTML.IHTMLElementCollection
Dim anchor As MSHTML.IHTMLElement
[[enter image description here](https://i.stack.imgur.com/g7cft.png)](https://i.stack.imgur.com/Ycog8.png)
usrname = ""
pass = ""
IE.Visible = True
IE.navigate ("")
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set MSDOC = IE.document
Set inputs = MSDOC.getElementById("signOnName")
inputs.Value = usrname
Set inputs = MSDOC.getElementById("password")
inputs.Value = pass
Set singin = MSDOC.getElementById("sign-in")
singin.Click
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Do Until IE.readyState = 4
DoEvents
Loop
Set Anchor = MSDOC.getElementsByTagName("img")
For Each anchor In Anchors
if anchor.innertext = "Prize Bonds" then
anchor.click()
End if
Exit for
Next anchor
End Sub
我已经描述过,我使用不同的方法来访问正确的 HTML 元素并单击它,但它们不起作用
答: 暂无答案
评论