html - 我想单击 VBA 中的按钮
问题描述
我是初学者和非技术人员,我完全被困在这里
我想使用 VBA 单击新建项目按钮
这是新项目按钮的检查元素
<button tabindex="0" class="xui-button xui-button-create xui-button-small" type="button" data-automationid="project-modal-new-button">New project</button>
下面是我到目前为止创建的代码,它运行没有任何问题,它将带我从项目选项卡转到项目选项卡我需要使用 VBA 单击新的项目按钮
Sub Xero()
Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
i.Visible = True
i.navigate ("https://login.xero.com/")
Do While i.readyState <> READYSTATE_COMPLETE
Loop
Dim idoc As MSHTML.HTMLDocument
Set idoc = i.document
idoc.all.UserName.Value = "XXXXX"
idoc.all.Password.Value = "123"
Dim ele As MSHTML.IHTMLElement
Dim eles As MSHTML.IHTMLElementCollection
Set eles = idoc.getElementsByTagName("button")
For Each ele In eles
If ele.ID = "submitButton" Then
ele.Click
Application.Wait (Now + TimeValue("0:00:10"))
Else
End If
Next ele
i.navigate ("https://projects.xero.com/?CID=!QhJgj")
Do While i.readyState <> READYSTATE_COMPLETE
Loop
End Sub
我想单击“新建项目”按钮以进一步移动
解决方案
尝试使用 css 类选择器(相同的想法getElementsByClassName
但更快)
While i.Busy Or i.readyState < 4: DoEvents: Wend
Application.Wait Now + Timeserial(0,0,2)
i.document.querySelector(".xui-button-create").click
此外,使用适当的页面等待之后.click
,.navigate
即
While i.Busy Or i.readyState < 4: DoEvents: Wend
因此,在 .navigate 和尝试单击按钮之间进行适当的等待,然后在单击按钮后再次等待。
推荐阅读
- typescript - 如何在打字稿中记录联合类型?
- json - 从序列化 Django REST API 中的字段中排除特定实例
- python - 如何在创建用户帐户 Django 之前让用户付费
- c++ - C++中模板方法的返回类型
- sql - 比较同一张表oracle中的数据
- python - 如何增加使用 seaborn 构建的热图的大小?
- android - Android 11 (API 30) 中的导航栏不完全透明
- java - Facebook 图表,跳过分享对话框
- amazon-web-services - 使用 aws cli 将 S3 对象 url 上传到存储桶后如何获取它?
- sql - 使用在 Oracle SQL 中给出错误的 Case 语句进行更新