更新时间:2023-09-12 15:52:34
如果仅对该选项卡感兴趣,我将首先使用css类选择器按其类名获取包含所有选项卡的父元素(div).然后,我将结合使用子组合器和nth-child()选择器,以按其类名抓取第二个子div:
If only interested in that one tab I would first grab the parent element (div), which houses all the tabs, by its classname using a css class selector. I would then use a child combinator in combination with nth-child() selector to grab the second child div by its classname:
.querySelector(".table-view__tabs > div:nth-child(2)").Click 'Select tab direct
如果可能对所有3个标签感兴趣:
If potentially interested in all 3 tabs:
我首先要使用css类选择器按其类名获取包含所有选项卡的父元素(div).然后,我将使用子组合器按其类名来获取子div(即选项卡).我将索引到返回的nodeList中以单击所需的选项卡:
I would first grab the parent element (div), which houses all the tabs, by its classname using a css class selector. I would then use a child combinator to grab the child divs (which are the tabs) by their classnames. I would index into the returned nodeList to click the required tab:
Set tabs = .querySelectorAll(".table-view__tabs > div") 'select all tabs then index in for tab of choice
tabs.Item(1).Click
VBA:
Option Explicit
Public Sub ClickButton()
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
With ie
.Visible = True
.Navigate2 "https://fundcentres.lgim.com/uk/workplace-employee/fund-centre/#Product=WorkSave-Pension-Plan-(generation-3)"
While .Busy Or .ReadyState <> 4: DoEvents: Wend
With .Document
.querySelector(".table-view__tabs > div:nth-child(2)").Click 'Select tab direct
Stop 'Delete me later
Dim tabs As Object
Set tabs = .querySelectorAll(".table-view__tabs > div") 'select all tabs then index in for tab of choice
tabs.Item(1).Click '0 based so first tab is 0, second is 1 etc
Stop 'Delete me later
End With
Stop '<==Delete me later
.Quit
End With
End Sub
阅读:
参考(VBE>工具>参考):