【问题标题】:VBA control a drop down menuVBA控件下拉菜单
【发布时间】:2016-02-24 16:09:55
【问题描述】:

我正在尝试控制website 上的下拉列表,但由于某种原因无法与之交互。这是我认为从下拉菜单中负责的 HTML 部分:

    <div id="content">
        <div id="main">
            <div class="container">
                <div class="formBody">
                    <h1>Get a Quote</h1>
                    <div style="width:215px; height:35px;" class="noBottomSpacing">
                      <select id="quoteDropdown" name="position">
                            <option>Select Type of Quote</option>
                            <option value="ltl">LTL Quote</option>
                            <option value="truckload">Truckload Quote</option>
                            <option value="expedited">Expedited Quote</option>
                            <option value="Mexico">Mexico Quote</option>
                        </select>
                    </div>

                </div>
                <br />
                <div class="quoteContent">
                </div>
            </div>
        </div>

我尝试了几种不同的 VBA sn-ps,但似乎没有任何效果。

    ie.Document.getElementbyID("quoteDropdown").selectedindex = 1
    ie.Document.getElementbyID("quoteDropdown").Item(0).Value = 1
    ie.Document.getElementbyID("quoteDropdown").Value = "ltl"

如果有人有任何指导,我将不胜感激。谢谢!

【问题讨论】:

  • 你可以试试 ie.Document.getElementbyName("position")(0).Value = "ltl"

标签: html vba excel


【解决方案1】:

类似

Dim ie As SHDocVw.InternetExplorer
Dim d As MSHTML.IHTMLSelectElement

Set ie = New InternetExplorer
ie.Visible = 1

ie.navigate "http://www.saia.com/RequestQuote.aspx"

While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
    DoEvents
Wend

Set d = ie.document.getElementById("quoteDropdown")

'     Then use d.selectedindex or d.item(1).text d.value etc.

查看网页源代码,是从每个内部项目上的点击事件处理的,因此您需要获取这些,然后触发点击事件

从页面" $('#quoteDropdown').val('ltl').trigger('click').selectric('refresh'); loadquote('ltl');"

【讨论】:

    【解决方案2】:

    好的,我明白了。感谢 Nathan_Sav 向我指出该声明。此代码正在更改索引,但没有触发事件。

    ie.document.getElementbyID("quoteDropdown").selectedindex = 1
    

    为了触发事件,我必须调用函数“loadquote”

    ie.document.parentWindow.execScript "loadquote('ltl')"

    这成功地调用了函数“loadquote”并更新了页面。

    【讨论】:

      猜你喜欢
      • 2021-07-21
      • 1970-01-01
      • 2012-10-01
      • 2019-11-02
      • 1970-01-01
      • 2023-03-15
      • 2017-05-10
      • 1970-01-01
      相关资源
      最近更新 更多