Excel 在vba中使用.Document.getElementById()和变量
我试图使用vba从下拉框中选择值,下拉框的代码块如下Excel 在vba中使用.Document.getElementById()和变量,excel,vba,Excel,Vba,我试图使用vba从下拉框中选择值,下拉框的代码块如下 <input type="text" id="form_autocomplete_input-1542902425322" list="form_autocomplete_suggestions-1542902425322" placeholder="Search keyword or select filter" role="combobox" aria-expanded="false" autocomplete="off" auto
<input type="text" id="form_autocomplete_input-1542902425322" list="form_autocomplete_suggestions-1542902425322" placeholder="Search keyword or select filter" role="combobox" aria-expanded="false" autocomplete="off" autocorrect="off" autocapitalize="off" aria-autocomplete="list" aria-owns="form_autocomplete_suggestions-1542902425322 form_autocomplete_selection-1542902425322">
如果表单自动完成建议-1542902425322
的值是静态的,我会使用Document.getElementById(“表单自动完成建议-1542902425322”).value=“Role:Student”
,但这似乎是随机生成的数值
我看了一下,似乎不能简单地在.Document.getElementById(“form\u autocomplete\u suggestions-*”)中添加通配符。Value=“Role:Student”
由于它是随机生成的,而且是一个很长的数字,所以它不能在一个值数组中循环。所以我不确定如何解决这个问题。您可以使用css属性等于值选择器语法和
^
运算符来表示从某个子字符串开始。您也可以使用*
代替,这意味着包含
[id^='form_autocomplete_input-']
VBA:
ie.document.querySelector("[id^='form_autocomplete_input-']")
您还可以使用:
[placeholder='Search keyword or select filter']
这将是:
ie.document.querySelector("[placeholder='Search keyword or select filter']")
当您指出需要选择此选项时,您可能需要:
ie.document.querySelector("[id^='form_autocomplete_input-']").Selected = True
参考资料:
ie.document.querySelector("[id^='form_autocomplete_input-']")
那么表单上会有多少文本框?您不必在数字数组中循环,您可以查看提供的选项,从
.getElements
等开始,将它们放到集合中,并在必要时循环这些选项。你能用对象的数量再解释一下吗,或者粘贴一张页面的屏幕截图。?嗨,不知道你所说的形式是什么意思?问题是下拉框的值发生了变化!因此,我无法使用.Document.getElementById(“form\u autocomplete\u suggestions-1542902425322”).Value=“Role:Student”
,因为1542902425322的值现在已更改为其他值。您尝试过吗?