I';我将属性findelements与selenium和C#一起使用,但它始终给出相同的错误

I';我将属性findelements与selenium和C#一起使用,但它始终给出相同的错误,c#,selenium,C#,Selenium,这是我试图用来获取各个元素的代码的一部分,但它一直给我以下错误: System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]或 其他相同 这也显示在datagridview的行中 IList<IWebElement> ruas = Gdriver.FindElements(By.ClassName("search-title")); String[] AllText = new St

这是我试图用来获取各个元素的代码的一部分,但它一直给我以下错误:

System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]或 其他相同

这也显示在datagridview的行中

IList<IWebElement> ruas = Gdriver.FindElements(By.ClassName("search-title"));
String[] AllText = new String[ruas.Count];
int i = 0;
foreach (IWebElement element in ruas)
{

     AllText[i++] = element.Text;
     table.Rows.Add(ruas);     
}
IList ruas=Gdriver.FindElements(By.ClassName(“搜索标题”);
String[]AllText=新字符串[ruas.Count];
int i=0;
foreach(ruas中的IWebElement元素)
{
AllText[i++]=element.Text;
表.行.添加(ruas);
}

第一件事是:据我所知,表中不包含您所讨论的元素。这是一个列表:
(考虑到您在网站链接中留下的评论)

如果要查找这些元素,可以使用以下代码:

var elements = driver.FindElements(By.CssSelector("ul.list-inline > li > a"));

// Here you can iterate though links and do whatever you want with them
foreach (var element in elements)
{
    Console.WriteLine(element.Text);
}

// Here is the collection of links texts
var linkNames = elements.Select(e => e.Text).ToList();

考虑到您得到的错误,我可以假设您正在使用存储收集的数据,这是非常不正确的。用于查看MVC应用程序中的数据。没有用于存储表数据的标准Selenium类。这有多种方法,但我不能给你任何建议,因为我不知道你想要实现什么。

以下是我如何回答我自己的问题的:

IList<string> all = new List<string>();
        foreach (var element in Gdriver.FindElements(By.ClassName("search-title")))
        {
            all.Add(element.Text);
            table.Rows.Add(element.Text);
        }
IList all=new List();
foreach(Gdriver.FindElements(By.ClassName(“搜索标题”))中的var元素)
{
all.Add(element.Text);
table.Rows.Add(element.Text);
}

您能否提供有关错误的更多信息?错误的确切类型名称(包括其前面的名称空间)和确切的错误消息?当我的代码转到相应的站点并向datagridview拾取元素时,会显示我的错误,并且在行中出现此错误:System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]首先,谢谢,如果链接是这个,而你要得到每个地址的第一张底片,蓝色底片,你会怎么做?@PedroAlvim,这也不是一张表。获取新链接中提供的元素文本的方法与此完全相同。唯一的区别在于选择器。在第二种情况下,它将是CssSelector:“
div.places>p>span>a.search-title
”,它使用的代码与我已经提供的代码相同。@PedroAlvim,这也是一篇关于Selenium中选择器的好文章。它包含基本案例。完成此操作后,您可以在W3C学习更多高级案例: