我正在测试一个选择元素。我需要断言该Select元素内不存在带有用户指定文本的特定选项,并且还断言SelectElement中确实存在具有用户指定文本的另一个选项。

最佳答案

这将工作:

public bool OptionListContains(SelectElement select, string expectedValue)
{
    IList<IWebElement> options = select.Options;
    List<string> optionsText = options.Select(a => a.Text).ToList();
    return optionsText.Contains(expectedValue);
}


以防万一您在需要之前没有使用过LINQ查询:

using System.Linq;

关于c# - 通过Selenium检查SelectElement元素内是否存在选项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42008989/

10-11 15:20