我正在尝试使用excel VBA从下面的时间选择器中选择09。我已经到了下面一行,但不知道如何继续。非常感谢任何帮助。
Set e = appIE.document.getElementbyid("timepicker-pickup")
<div class="timepicker" id="timepicker-pickup">
<div class="arrow"></div>
<div class="icon close-btn"></div>
<div class="inner-time-picker clearfix">
<div class="section hours">
<div class="up-arrow"><span class="icon arrow"></span></div>
<div class="selectors">
<ul>
<li data-value="00">00</li>
<li data-value="01">01</li>
<li data-value="02">02</li>
<li data-value="03">03</li>
<li data-value="04">04</li>
<li data-value="05">05</li>
<li data-value="06">06</li>
<li data-value="07">07</li>
<li data-value="08" class="selected">08</li>
<li data-value="09">09</li>
<li data-value="10">10</li>
<li data-value="11">11</li>
</ul>
</div>
<div class="down-arrow"><span class="icon arrow"></span></div>
答案 0 :(得分:1)
尝试选择器#timepicker-pickup li:nth-child(10)
appIE.document.querySelector("#timepicker-pickup li:nth-child(10)").Click
#
的意思是className,因此选择className为li
的元素中的第10个timepicker-pickup
标记
或选择器#timepicker-pickup [data-value='09']
appIE.document.querySelector("#timepicker-pickup *[data-value='09']").Click
这只是一个缩写,我在data-value='09'
的className中查找属性为timepicker-pickup
的任何东西
我测试了最新的作品。
CSS选择器:
VBA代码:
Public Sub test()
Dim ieApp As InternetExplorer, URL As String
URL = "https://www.europcar.co.za/"
Set ieApp = New InternetExplorer
With ieApp
.Visible = True
.navigate URL
While .Busy Or .readyState < 4: DoEvents: Wend
.document.querySelector("#timepicker-pickup [data-value='09']").Click
Stop '<== Delete me
'.Quit <'== Uncomment me
End With
End Sub