我正在尝试设置下拉框的值,并显示一个甚至不是选项的空白。VBA无法通过选择下拉菜单获得选项
下面是HTML剪断,它(注:内部网站,所以我不能给URL或太多)
<select id="entNo" name="entNo" style="width:75px">
<option selected="selected" value="All">All</option>
<option value="650101">650101</option>
<option value="66">66</option>
这里是它的功能。
function requestEntities()
{
var ele = document.getElementById('entNo');
if (ele) {
ele.options.length = 0;
ele.options[0] = new Option('All');
ele.disabled = true;
ele = document.getElementById('divNo');
if (ele) {
var i = ele.selectedIndex;
var div = ele.options[i].value;
sendHttpRequest('http://example.com/cgi-bin/wspd_cgi.sh/WService=wslive//wpr/entityList.r?div=' + div);
}
}
}
我使用VBA代码是这样的:
Set objCollection = ie.document.getElementsByTagName("select")
'Debug.Print objCollection.Length
i = 1
While i < objCollection.Length 'Loop to locate and change the fields with proper data using the "select" tags
Debug.Print objCollection(i).Value
If objCollection(i).Name = "entNo" Then
If ecode <> "" Then
Debug.Print objCollection(i).Value
objCollection(i).Value = ecode
End If
ElseIf objCollection(i).Name = "curStatus" Then
objCollection(i).Value = "Open"
ElseIf objCollection(i).Name = "opStatus" Then
objCollection(i).Value = "All"
End If
i = i + 1
Wend
我不能给更多的,因为这是工作。我已经耗尽谷歌搜索。
另一件奇怪的事情是,当我单步执行时它会起作用。否则就无法工作。 任何建议将不胜感激。
我无法获得当前选定的值。 – user3490906
如果这些select元素在某种程度上是依赖的(改变其中一个会改变下一个可用的选项),那么你需要等待下一个填充,这就是为什么它在单步执行时工作,但不是如果你直接运行整个事情。 –