internet-explorer - 使用 VBA Excel 通过更改下拉值来导航网站

标签 internet-explorer excel drop-down-menu vba

我正在编写一个 Excel 宏,它将导航到公用事业公司网站,然后下载链接到该帐户的所有报表。要访问报表下载页面,我需要导航到每个帐户的摘要页面。所有帐户都列在下拉列表中 - 当我手动单击列表中的其他帐户时,页面会更新为新帐户。使用我从 this question 获得的提示,我能够获取宏来更改下拉值。问题是,即使它从列表中选择新值,页面也不会更新到新帐户。不幸的是,没有指向每个帐户页面的直接链接,因为下拉列表似乎将一个值传递给脚本。我尝试从不同的帐户复制网址,但无论哪个帐户,网址上的网址都是相同的。以下是有问题的 VBA 代码:

Do While i < intNumberAcct
    ie.document.getElementById("ctl00_PageContent_AccountDropDown_BillingAccountsDropDown").selectedindex = i
    Call downloadStatement
    i = i + 1
Loop

我尝试在更改下拉列表值后刷新 IE,但是当它刷新时,它会恢复为下拉列表中的原始值。我还尝试了 ie.document.getElementById("ctl00_PageContent_AccountDropDown_BillingAccountsDropDown").Click 选择新索引后,但没有任何效果。

这是下拉列表的 html 源代码 - 我删除了一大块帐户,这样它就不会那么长,并用“x”混淆了帐号和地址:

<table style="width: 100%" cellpadding="0" cellspacing="0">
<tr>
    <td valign="top" class="AccountDropDownLabelCells" style="height: 25px;">
        <strong>Billing Account:</strong>
    </td>
    <td valign="top" style="text-align: left" align="left">
        <select name="ctl00$PageContent$AccountDropDown$BillingAccountsDropDown" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$PageContent$AccountDropDown$BillingAccountsDropDown\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_PageContent_AccountDropDown_BillingAccountsDropDown" style="width:250px;">
          <option value="xxxxx">xxxxx(16 xxxxx Dr)</option>
          <option selected="xxxxx" value="xxxxx">xxxxx(18 xxxxxDr)</option>
          <option value="xxxxx">xxxxx(20 xxxxx Dr)</option>
          <option value="xxxxx">xxxxx(22 xxxxxDr)</option>
          <option value="xxxxx">xxxxx(28 xxxxx Dr)</option>
          <option value="xxxxx">xxxxx(30 xxxxxDr)</option>
          <option value="xxxxx">xxxxx(34 xxxxxDr)</option>
</select>
        &nbsp;
    </td>
</tr>


</table>

任何有关如何在下拉列表中选择页面后将页面更新到新帐户的想法将不胜感激。

最佳答案

一旦设置了下拉列表的索引,您就需要触发更改事件。

select name="ctl00$PageContent$AccountDropDown$BillingAccountsDropDown" onchange="javascript:setTimeout('__doPostBack(\'ctl00$PageContent$AccountDropDown$BillingAccountsDropDown\',\'\')', 0)" id="ctl00_PageContent_AccountDropDown_BillingAccountsDropDown" style="width:250px;"

doc.getElementById("xs_r_gender").selectedindex=1
doc.getElementById("xs_r_gender").FireEvent("onchange")

关于internet-explorer - 使用 VBA Excel 通过更改下拉值来导航网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16347898/

相关文章:

c# - Internet Explorer 8中的“This webpage could not be saved”错误

javascript - 错误: Not Implemented Code 0

jquery - 使用 jQuery 1.5 对编码的国际化域名进行 Ajax 调用在 Internet Explorer 中不起作用?

excel - 由于数字格式为文本,将 Excel 文件读取到 Python 失败

excel - 将唯一值分配给数组

excel - 打开数据验证下拉列表后立即触发 VBA 宏?

javascript - 滑动下拉菜单

javascript - IE - 上传新图像时,显示旧图像

CSS 下拉菜单在 IE9 及更低版本中不起作用

android - Phonegap - 下拉菜单不可点击(Android 和 iOS)