【发布时间】:2017-08-31 09:32:22
【问题描述】:
我正在使用 VBA 打开网站、登录并导航到某个页面。有一个包含 8 个选项的下拉菜单。
我使用此代码将下拉列表更改为我想要的值,但在我继续时它总是恢复为默认值。如何锁定此更改?
Set Element = IE.Document.getElementsByName("date_range")
Element.Item(0).Value = "custom"
这是页面代码:
<div class="SelectInput">
<select class="SelectInput-select" name="date_range">
<option value="all_time">All Time</option>
<option value="today">Today</option>
<option value="yesterday">Yesterday</option>
<option value="this_month">Month to date</option>
<option value="last_month">Last Month</option>
<option value="this_year">Year to date</option>
<option value="last_year">Last year</option>
<option value="custom">Between...</option>
</select>
<div class="SelectInput-arrows">...</div>
</div>
谢谢,
【问题讨论】:
-
您能否发布该页面的链接或类似内容以测试您的代码?
-
这是通过点击事件处理的,还是所有 8 个选项都硬编码在 HTML 页面中?对于第一个,您可以尝试
IE.Document.getElementById("the id you have").SelectedIndex = 0。第二个,你可以试试IE.Document.getElementById("the id you have").Value = "custom"。 -
我无法发布链接,它位于登录页面的后面。我添加了该部分的代码。没有元素 ID,只有名称
标签: vba excel internet-explorer-11