Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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
C# 我想选择下拉元素_C#_.net_Selenium - Fatal编程技术网

C# 我想选择下拉元素

C# 我想选择下拉元素,c#,.net,selenium,C#,.net,Selenium,我想单击一个下拉元素。我已经提到了元素的xpath/css。但它不断地给出错误“找不到元素”。我正在研究C#on selenium。我也先给出了下拉ID,然后等待下拉元素,然后点击它,但它总是给出相同的错误。有什么想法吗?这取决于可用的iFrame,或者您应该切换到默认内容。这很复杂,没有你的代码 无论如何,试试这个代码。这对我有用: private static void ChooseZipCode(IWebDriver wd) { if (!wd.FindElement(By.XPa

我想单击一个下拉元素。我已经提到了元素的xpath/css。但它不断地给出错误“找不到元素”。我正在研究C#on selenium。我也先给出了下拉ID,然后等待下拉元素,然后点击它,但它总是给出相同的错误。有什么想法吗?

这取决于可用的iFrame,或者您应该切换到默认内容。这很复杂,没有你的代码

无论如何,试试这个代码。这对我有用:

private static void ChooseZipCode(IWebDriver wd)
{
    if (!wd.FindElement(By.XPath("//td[@id='divShipStateCombo']/select//option[3]")).Selected)
    {
        wd.FindElement(By.XPath("//td[@id='divShipStateCombo']/select//option[3]")).Click();
    }
}
// where is "[3]" the position your element(ID) in drop down menu
// or
private static void SelectElement(IWebDriver wd, string CardType)
{
    SelectElement cardSelect = newSelectElement(wd.FindElement(By.Name("CardType")));
    cardSelect.SelectByText("Visa Card");
}

请用您正在使用的代码编辑您的问题。