Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gecko或JavaScript在组合框中选择一个选项_Javascript_C#_Gecko - Fatal编程技术网

Gecko或JavaScript在组合框中选择一个选项

Gecko或JavaScript在组合框中选择一个选项,javascript,c#,gecko,Javascript,C#,Gecko,请注意,我试图在“ComboBox”中选择一个选项,但“optionElement.Selected=true;”不起作用。我用对了吗?有必要在之前发出另一个命令吗?我有一个辅助函数和一个主函数的延伸。详细信息:“pdcme\u cd\u tipo\u ac”是一个“文本框”: // MAIN FUNCTION // ... var optionElements = oGecko.Document.GetElementsByTagName("option"); foreach (Gecko

请注意,我试图在“ComboBox”中选择一个选项,但“optionElement.Selected=true;”不起作用。我用对了吗?有必要在之前发出另一个命令吗?我有一个辅助函数和一个主函数的延伸。详细信息:“pdcme\u cd\u tipo\u 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;
    }
}

@Jawad,我的意思是它没有单击或没有选择。您是否尝试过OptioneElement.Selected.SetAttribute(“value”,true)@“Selected”中的Jawad没有方法“SetAttribute”。您是否在NuGet中导入了任何额外函数?@Jawad,->“bool”不包含“SetAttribute”的定义,并且找不到任何可访问的“SetAttribute”扩展方法,该扩展方法接受类型为“bool”的第一个参数(是否缺少程序集使用策略或引用?)optionElement.SetAttribute(“Selected”,“true”);使用字符串而不是布尔