我是初学者,不是技术人员,我完全被困在这里
我想使用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
我想单击“新建项目”按钮以进一步移动
答案 0 :(得分:0)
尝试使用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和尝试单击该按钮之间进行适当的等待,然后在单击该按钮之后再次尝试。