硒检查列表中的文本 [英] Selenium to check text in a list

查看:57
本文介绍了硒检查列表中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如代码中所示的元素列表.我将其更改为Array.在我的应用程序启动之前,用户将在文本框中输入一些文本.

I have a list of elements as shown in the code. And I am changing it to Array. Before my application starts, the user will enter some text in a text box.

C#代码:

IList<IWebElement> namelist = driver2.FindElements(By.TagName("SPAN"));
namelist.ToArray();

我想做的是:检查该列表中是否存在用户输入的文本.

What I want to do is : to check whether text entered by the user is present in that list.

假设用户输入"String Text",那么我需要硒来检查此列表中是否存在字符串文本".

Suppose the user enters "String Text", then I need selenium to check whether "String Text" is present in this list.

推荐答案

只需将元素数组转换为List,然后使用

Just convert your array of elements to List and then verify presence of text with Any function from System.Linq namespace:

// Get text entered by the user
string checkText = "String Text";

if (namelist.ToList().Any(span => span.Text.Contains(checkText)))
{
    // List contains text
}
else
{
    // List does not contain text
}

这篇关于硒检查列表中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆