[请尝试在'ComboBox'中选择一个选项,但是“ optionElement.Selected = true;”不起作用。我使用正确的方式吗?有必要在之前发出另一个命令吗?我有一个辅助功能和一个主要功能。详细信息:“ pdcme_cd_tipo_ac”是一个“文本框”:
// MAIN FUNCTION
// ...
var optionElements = oGecko.Document.GetElementsByTagName("option");
foreach (GeckoOptionElement optionElement in optionElements)
{
//2019-12-06 - Fabio I. - If the combo is "ID = #cd_type" (because it takes ALL options from ALL combos!);
if (optionElement.Parent.Id == "#cd_type")
{
if (optionElement.Label.ToUpper() == "APPLICATION")
{
optionElement.Selected = true;
SetTextInput_ID("pdcme_cd_tipo_ac", optionElement.Label);
break;
}
else if (optionElement.Label.ToUpper() == "TOTAL RESCUE")
{
optionElement.Selected = true;
SetTextInput_ID("pdcme_cd_tipo_ac", optionElement.Label);
break;
}
else if (optionElement.Label.ToUpper() == "REDEMPTION LIQUID VALUE")
{
optionElement.Selected = true;
SetTextInput_ID("pdcme_cd_tipo_ac", optionElement.Label);
break;
}
// ...
}
}
private bool SetTextInput_ID(string ID,
string ValueID)
{
GeckoElement ele;
try
{
ele = oGecko.Document.GetElementById(ID);
if (ele == null) return false;
if (ele.GetType().ToString() != "Gecko.DOM.GeckoInputElement") return false;
((GeckoInputElement)ele).Focus();
((GeckoInputElement)ele).Value = ValueID;
((GeckoInputElement)ele).Click();
return true;
}
catch (Exception ex)
{
return false;
}
}
来自:https://stackoverflow.com/a/16872628/1390548
要设置值,请使用以下代码:
optionElement.SetAttribute("Selected", "true");