我把头靠在墙上 - 有人请帮忙。
使用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代码中看到的那样,我已经将值设置为“Detached”,并且通过故障排除我设置了selected = selected。但无济于事,它仍然会在页面上改变价值。我对geckofx做错了什么!!! HELLLP
在Visual Studio 2013中测试 - VB.NET:
Dim el1 As Gecko.DOM.GeckoSelectElement = _
GeckoWebBrowser1.Document.GetElementsByName("GarageType")(0)
el1.Options.item(<NUMBER>).Selected = True
对不起,代码只回答,因为我不会说英语。