我想单击VBA中的按钮

问题描述 投票:1回答:1

我是初学者和非技术人员,我完全被困在这里

我想使用VBA单击“新建项目”按钮

这是新项目按钮<button tabindex="0" class="xui-button xui-button-create xui-button-small" type="button" data-automationid="project-modal-new-button">New project</button>的inspect元素

下面是我到目前为止创建的代码,它运行没有任何问题,它将带我到项目选项卡的项目选项卡我需要使用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

我想单击“新建项目”按钮以进一步移动

html excel vba web-scraping
1个回答
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和单击按钮后再次单击按钮之间进行适当的等待。

© www.soinside.com 2019 - 2024. All rights reserved.