Html 单击带有<;span>;价值

Html 单击带有<;span>;价值,html,vba,button,Html,Vba,Button,我已经为此工作了几天了。我正在尝试浏览一个网站。我的下一步是点击一个按钮。不幸的是,URL取决于之前的选择,所以我不能只关注链接 以下是我尝试单击的按钮的HTML: 目前,我登录到一个网站,在搜索框中输入一个值,新信息弹出,我点击一个按钮。现在,在一个新的页面上,我想点击另一个按钮,但无法找到它 以下是我的VBA代码: Sub TestWebsite() Set ie = CreateObject("InternetExplorer.application") ie.Visible =

我已经为此工作了几天了。我正在尝试浏览一个网站。我的下一步是点击一个按钮。不幸的是,URL取决于之前的选择,所以我不能只关注链接

以下是我尝试单击的按钮的HTML:


目前,我登录到一个网站,在搜索框中输入一个值,新信息弹出,我点击一个按钮。现在,在一个新的页面上,我想点击另一个按钮,但无法找到它

以下是我的VBA代码:

Sub TestWebsite()

Set ie = CreateObject("InternetExplorer.application")

ie.Visible = True
ie.Navigate ("https://functionalmovement.com/login?return=%2F" & ActiveCell)
Do
    If ie.readyState = 4 Then
        ie.Visible = True
        Exit Do
    Else
        DoEvents
    End If
Loop
    ie.Document.forms(0).all("Username").Value = Range("B3")
    ie.Document.forms(0).all("Password").Value = Range("B4")
Do While ie.Busy
Loop
    ie.Document.forms(0).submit
Do While ie.Busy
Loop
    Application.Wait (Now + TimeValue("0:00:01"))
    ie.Navigate ("http://functionalmovement.com/pro/clients" & ActiveCell)
Do
    If ie.readyState = 4 Then
        ie.Visible = True
        Exit Do
    Else
        DoEvents
    End If
Loop
ie.Document.forms(1).all("gvClients$DXFREditorcol1").Value = Range("B6")
ie.Document.forms(1).all("gvClients$DXFREditorcol1").Select

SendKeys String:="{enter}", Wait:=True

Application.Wait (Now + TimeValue("0:00:03"))

SendKeys String:="{tab}"
SendKeys String:="{tab}"
SendKeys String:="{tab}"
SendKeys String:="{tab}"
SendKeys String:="{tab}"
SendKeys String:="{enter}"

Application.Wait (Now + TimeValue("0:00:10"))

这里是我希望代码单击按钮的位置。

由于您尝试单击的链接没有
id
,您需要通过标记名或类名找到它

如果
元素始终包含该文本,则可以使用
GetElementsByTagName()
返回所有
元素,然后找到与显示文本匹配的元素(
“创建新训练”

找到
后,可以使用
ParentElement
属性访问其父级,然后调用
Click()
函数

这应该可以做到:

Dim e
For Each e In ie.document.getElementsByTagName("span")
    If e.InnerText = "Create a New Workout" Then

        ' Found the <span>. Now click its parent (<a>)...           
        e.ParentElement.Click
        Exit For

    End If
Next
dime
对于ie.document.getElementsByTagName(“span”)中的每个e
如果e.InnerText=“创建新训练”,则
“找到了。现在单击它的父项()。。。
e、 父元素。单击
退出
如果结束
下一个

太棒了,谢谢!这很好地解决了其他一些问题。