Web浏览器从动态组合框中选择值

时间:2014-03-10 10:37:43

标签: html vb.net webbrowser-control

我正在尝试使用VB.NET的webbrowser控件自动填充表单

问题在于有两个组合框,第二个组合框的值根据第一个组合而生成。 我可以为第一个组合框选择正确的索引,但是对于第二个组合框,永远不会生成值。我必须为第一个组合框手动选择另一个值,然后填充第二个值。

我已尝试设置/移除第一个组合框的焦点以尝试让第二个组合填充,但这没有用。

我目前的代码是:

''Select from the first combo box
Dim make As HtmlElement
make = WebBrowser1.Document.GetElementById("cars.carmake_s")
make.SetAttribute("selectedIndex", 1)
WebBrowser1.Update()


''Should select the second value, but doesn't
Dim model As HtmlElement
model = WebBrowser1.Document.GetElementById("cars.carmake_s+cars.carmodel_s")
model.SetAttribute("selectedIndex", 2)
WebBrowser1.Update()

我正在玩的HTML代码是(缩减):

    <div class="form-row clearfix">
<label for="cars.carmake_s">
    Make<span class="orange">*</span>
    </label>
<div class="form-value">
    <div class="c-select-list c-slctbx-medium">
            <span class="c-icon c-icon-arrow-green-down"></span>
                <select id="cars.carmake_s" name="attributeMap[cars.carmake_s]" class="c-slctbx-depnode c-slctbx-medium" name="attributeMap[cars.carmake_s]"><option value="">Please choose</option>
                <option value="alpharomeo"
                                >
                            Alfa Romeo</option>

....
...
...                             
                    </select></div>
        </div>
    <div class="form-row clearfix">
<label for="cars.carmodel_s">
    Model<span class="orange">*</span>
    </label>
<div class="form-value">
    <div class="c-select-list c-slctbx-medium">
            <span class="c-icon c-icon-arrow-green-down"></span>
<!-->####This is the second combobox and gets populated depending on the first combobox<!-->
            <select id="cars.carmake_s+cars.carmodel_s" name="attributeMap[cars.carmodel_s]" class=" c-slctbx-medium" name="attributeMap[cars.carmodel_s]"><option value="">Please choose</option>
                </select></div>
        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法:

curElement.SetAttribute(&#34; Value&#34;,&#34; Value of Want&#34;)

curElement.RaiseEvent(&#34;平变化&#34)