HTMLInputElement 被点击,HTMLOptionElement 被点击
我正在尝试编写 vba 代码来填写网络表单并为我单击按钮。我循环浏览页面上的各种 option
标签以选择我想要的标签。当我到达它时,我想选择它,但我不确定语法。
Dim htmlO As HTMLOptionElement
For Each htmlO In Object.getElementByTagName("option")
If Trim(htmlO.value) = "INS" Then
htmlO.???? (click? select?)
Exit For
End If
Next
以下是网页中的 HTML:
<select gtbfieldid="40" id="menu" name="pv_choice">
<option selected="selected" value="ZZZ">Choose Menu Option
</option><option value="BL_COMP">Blanket Companies
</option><option value="CARR_SEARCH">Carrier Search
</option><option value="PASSWORD">Change Password
</option><option value="FED_REG">FMCSA Register
</option><option value="FEEDBACK">Feedback
</option><option value="HOME">Home Page
</option><option value="INS">Insurance Filing
</option><option value="OOS_LIST">Out Of Service Carriers
</option></select>
我想选择选项“INS”。
I'm am trying to write vba code to fill out web-forms and click buttons for me. I am looping through the various option
tags on the page to select the one I want. When I reach it, I want to select it, but I'm not sure of the syntax.
Dim htmlO As HTMLOptionElement
For Each htmlO In Object.getElementByTagName("option")
If Trim(htmlO.value) = "INS" Then
htmlO.???? (click? select?)
Exit For
End If
Next
Here is the HTML from the webpage:
<select gtbfieldid="40" id="menu" name="pv_choice">
<option selected="selected" value="ZZZ">Choose Menu Option
</option><option value="BL_COMP">Blanket Companies
</option><option value="CARR_SEARCH">Carrier Search
</option><option value="PASSWORD">Change Password
</option><option value="FED_REG">FMCSA Register
</option><option value="FEEDBACK">Feedback
</option><option value="HOME">Home Page
</option><option value="INS">Insurance Filing
</option><option value="OOS_LIST">Out Of Service Carriers
</option></select>
I want to select the option "INS".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我没有使用过 VBA,所以我提前道歉,但假设它使用与我熟悉的其他语言相同的 DOM 结构,请尝试:
这就是我在 javascript 中实现此目的的方法:)
HTH
I haven't used VBA so I apologize in advance but assuming it uses the same structure for the DOM than other languages I'm familiar with, try:
which is how I would achieve this in javascript :)
HTH
CSS 选择器:
这是一种更简单的方法。使用
option[value='INS']
CSS 选择器。这表示选择带有
option
标记的元素,该元素的属性value
的值为'INS'
。CSS 查询:
VBA:
CSS 选择器 通过 document 的“nofollow noreferrer">
.querySelector
方法。或者
CSS selector:
Here is a much simpler way. Use a CSS selector of
option[value='INS']
.This says select element with
option
tag that has attributevalue
whose value is'INS'
.CSS query:
VBA:
The CSS selector is applied via the
.querySelector
method ofdocument
.or
最终起作用的是......
我必须参考整个菜单并选择要选择的菜单,而不是选择单个选项。
What worked in the end was...
I had to reference the entire menu and choose which one to select, not select the individual option.