c# - 通过 Selenium 检查 SelectElement 元素中是否存在选项

标签 c# visual-studio selenium

我有一个正在测试的选择元素。我需要断言此 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 查询:

使用 System.Linq;

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

相关文章:

c# - TaskLocal<T> 类?

visual-studio - Visual Studio中的IntelliJ Shift Shift快捷方式(全局搜索)

javascript - 在 VS2013 中保持 javascript 函数折叠

c++ - Visual Studio 跨平台生成文件项目,找不到命令

python - Python 中的 Selenium 如果元素不存在,如何使用 If - else 代码

c# - 将父类(super class)传递给 C# 函数(带有 Java 序曲)

c# - 处理 UserControl 中异常的正确方法

html - 如何测试网页上粗体文本的百分比?

c# - Azure 函数队列触发器。连接字符串中可能存在错误绑定(bind)配置?

java - 如何点击 Span 类元素