Search code examples
c#listlinq

Select from list without having identifier


I am using linq to get data from website to List:

var HTMLTable = driver.FindElements(By.XPath("//*[@id=\"users_table\"]")).Select(e => e.Text).ToList();

Then I am using Console to see that data is in the List:

HTMLTable.ForEach(i => Console.Write("{0}\t", i));

Console shows table data as follow:

Firstname 
Lastname 
Type 
Crew 
JobTitle
DefaultPrice 
Future 
Language

Now I want to create a new list where Crew = "Employer". How to do that without having "column" names?

I have tried:

var OnlyOwnEmployees = HTMLTable.Where(x => x.[0] == "Employer").ToList();

But it says identifier expected and pointing to zero.


Solution

  • You need to use Where not Select. It should be .Where(x => x.Crew