vba - vba div角度选择选项
问题描述
我需要选择一个选项“我想选择这个”。我尝试了以下代码,但我收到了该对象所需的错误消息。这是我尝试过的元素示例之一
ie.document.getelementbyid("sys_select.incident.u_im_reporter_grp).option(1)
ie.document.getelementbyid("sys_select.incident.u_im_reporter_grp).option(0)
or
ie.document.getelementbyid("element.incident.u_im_reporter_grp").focus
ie.document.getelementbyid("element.incident.u_im_reporter_grp).click
如果您在下面看不到所有内容,请在评论回复中查看网站源代码。
<div class="section-content" id="ID123" glide="true">
<div class="row">
<div class="vsplit col-sm-6">
<div class="form-group is-required" id="element.incident.u_im_reporter_grp">
<div id="label.incident.u_im_reporter_grp"
nowrap="true" type="reference" data-type="label"
choice="1">
<label class=" col-xs-12 col-md-3 col-lg-4
control-label" dir="ltr"
onclick="return labelClicked(this);"
for="sys_select.incident.u_im_reporter_grp">
<span title="" class="required-marker
label_description"
id="status.incident.u_im_reporter_grp"
aria-label="Mandatory - must be populated before Submit"
data-original-title="Mandatory - must be populated before Submit" oclass=""
mandatory="true">
</span>
<span title="" class="label-text"
data-original-title="" data-html="false">
Reporter Group
</span>
</label>
</div>
<div class="col-xs-10 col-sm-9 col-md-6 col-lg-5 form-field input_controls">
<input name="sys_original.incident.u_im_reporter_grp"
id="sys_original.incident.u_im_reporter_grp"
type="hidden">
<input name="incident.u_im_reporter_grp"
class="direction:ltr"
id="incident.u_im_reporter_grp"
onchange="onChange('incident.u_im_reporter_grp')"
type="hidden" value="" mandatory="true">
<input name="sys_display.original.incident.u_im_reporter_grp"
id="sys_display.original.incident.u_im_reporter_grp"
type="hidden" value="">
<select name="sys_select.incident.u_im_reporter_grp"
class="form-control"
id="sys_select.incident.u_im_reporter_grp"
style="direction: ltr;"
onchange="onSelChange('sys_select.incident.u_im_reporter_grp');
updateAndFlip(this, 'incident.u_im_reporter_grp');">
<option value="">-- None --</option>
<option value="random value">I want select to this</option>
</select>
<input name="sys_display.incident.u_im_reporter_grp"
id="sys_display.incident.u_im_reporter_grp"
type="hidden" value="">
<script language="javascript">var select = gel('sys_select.incident.u_im_reporter_grp');
解决方案
尝试
While ie.Busy Or ie.readyState < 4: DoEvents: Wend
Dim a As Object
Set a = ie.document.querySelector("option[value='random value']")
a.Selected = True
这使用了一个 CSS 选择器option[value='random value']
,它查找第一个元素,作为使用querySelector
方法来应用,带有标签option
,其属性value
值为'random value'
。
根据您在评论中的 HTML,这将是 CSS 查询结果:
这个 。Selected
部分代码假定元素是可选择的。然而,我也展示了如何将元素设置为变量。