c# - Selenium C# 断言失败但有效

标签 c# selenium

好的,我在这里遗漏了一些东西。我的断言失败了,但看看本地人,我的值(value)和返回匹配。厌倦了看这个。我错过了什么?

代码:

        List<String> item = new List<string>();
        // grab the cells that contain the popsockets you want to sort
        IReadOnlyList<IWebElement> cells = Driver.FindElements_byXpath("//h2[@class='link']/a");

        // loop through the popsockets and assign the price into the ArrayList
        foreach (IWebElement cell in cells)
        {
            item.Add(cell.Text);
            Assert.IsTrue(item.Contains(value));
        }

本地人:

enter image description here

最佳答案

您是在列表本身而不是列表中的项目上调用 .contains()。所以它正在寻找对值的引用而不是单词。

Assert.IsTrue(item.Any(itm => itm.Contains(value)));

参见 List.Contains()

关于c# - Selenium C# 断言失败但有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57948036/

相关文章:

python-3.x - 如何通过 selenium python 以文本区域形式(在 HTML 标记中)添加文本?

javascript - Protractor - 获取元素的子元素?

java - Selenium:动态按钮和类?

c# - 允许对象移动的 WPF 容器

c# - 在 C#.net 中,如何获取发送到普通办公打印机打印的文件内容

c# - WPF 从后台工作人员更新状态栏文本

java - 未应用last()

ruby - 如何在每种情况下使用 Capybara 重启浏览器?

c# - 在编译时不知道目标类型的情况下设置属性

c# - c#访问内存地址