c# - 如果元素在表格上的元素内部有文本,则测试失败

标签 c# selenium-webdriver

您好,这是我的第一个问题,我希望有人能帮助我:)

我想检查 table 上是否存在带有文本的项目。如果存在我想测试失败。

internal static bool IsElementWithTextInCollection(ReadOnlyCollection<IWebElement> table, string customerFieldName)
{
    foreach (var item in table)
    {
        if (item.Text.(customerFieldName))
        {

        }
    }
        return true;
}

最佳答案

您应该检查项目中的文本 Contains 是否对结果给出 false 并打破循环。

internal static bool IsElementWithTextInCollection(
    ReadOnlyCollection<IWebElement> table, string customerFieldName)
{        
    bool result = true;
    foreach (var item in table)
    {
        if (item.Text.Contains(customerFieldName))
        {
            result = false;
            break;
        }
    }

   return result;
}

关于c# - 如果元素在表格上的元素内部有文本,则测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41056830/

相关文章:

c# - MVVMLight 和平台特定的服务实现

python - 默认调用父构造函数?

javascript - 如何通过 webdriverio wdio 文件更改 selenium-standalone 端口号?

java - 通过 CLI : Could not find or load main class org. testng.TestNG 执行 testng.xml 时出错

c# - 根据类次列表创建时间表的摘要说明

c# - Visual Studio 2010 无法使用 System.Threading.Tasks;

c# - 如何使用 Gmail SMTP 服务器在 C# 中发送邮件?

c# - 从 request.querystring 中删除字符

java - 无法将文本设置为隐藏输入

selenium - 在运行时将值传递给 xpath