使用GECKOFX Webcontrol VB.net选择DropDownBox值

时间:2015-06-04 20:43:10

标签: html vb.net geckofx

我把头靠在墙上 - 有人请求帮助。

使用IE webbrowser我只使用以下内容。

收集为htmlcollection = htmldoc.getelementbytagname(" select")

for each ele in collection
  dim options = ele.children
'some if thens to match the option to the option i need selected
ele.setattribute("value",optionselectedbyuser)

所有这些都很有效,它设置了值并在网页下拉框中选择了它。现在该网站需要Firefox我必须重做我的编码和下拉框正在杀了我这是我试过的

 dim collection as gecko.geckoelementcollection =htmldoc.getelementbytagname("select")

     for each ele as gecko.element in collection
        'some if thens to make sure im in the correct dropdown control
            for each child in ele.childnodes
              'using this to obtain the options of the dropdownbox and make sure it matches what user has selected, if it does i assign the element that value
                 if child.textcontent.tostring.toupper = inputfromusertoselect.toupper then
                    ele.setattribute("value",child.nodevalue("value"))
                 end if
             next
      next

在分配值之后,我重读了outerhtml代码,我设置的值现在在html中但在网页上没有选择实际项目。我还注意到在outerhtml中有一个带有自己值的选项标记。我想知道这是否是我需要设置值但我似乎无法分配选项的值。见外部html

  <select selected="selected" value="Detached" id="GarageType" name="GarageType" class="required"><option value="">-- Select Garage Type --</option>
          <option id="GarageTypeNone" value="None">None</option>
          <option id="GarageTypeAttached" value="Attached">Attached</option>
          <option id="GarageTypeDetached" value="Detached">Detached</option>
          <option id="GarageTypeCarport" value="Carport">Carport</option>
          <option id="GarageTypeBuiltIn" value="Built In">Built In</option></select>
你可以在html代码中看到,我已经将值设置为&#34; Detached&#34;并通过故障排除我设置所选=选择。但无济于事,它仍然会在页面上改变价值。我对geckofx做错了什么!!! HELLLP

1 个答案:

答案 0 :(得分:-1)

在Visual Studio 2013中测试 - VB.NET:

Dim el1 As Gecko.DOM.GeckoSelectElement = _ 
    GeckoWebBrowser1.Document.GetElementsByName("GarageType")(0)

el1.Options.item(<NUMBER>).Selected = True

很抱歉,代码只回答,因为我不会说英语。