简体   繁体   中英

Selenium C#, IList<IWebElement> Iterate through and Assert Values

Any help would be appreciated.

Firstly, I'm using pageObject, and I have the following element.

[FindsBy(How = How.Xpath, Using = ".//*[@id='control-content']/div/tbody/th")]    
public IList<IWebElement> TableHeaders { get; set; }

In this Ilist it should collect all values within the main column header.

I instantiate the class in the relevant page for script.

pageModule pm = new PageModule();

In the relevant page. I call the element.

var values = pm.TableHeaders;

Then II set a list

List<String> nameFilters = new List<String>(){
"Name",
"Name2",
}

foreach(var value in Values){
  Console.WriteLine("The value is : ") + values);
}

This is for the outputting the text in the ilist, I want to check the values match the Ilist and The string list.

I want to iterate through the list of these and check that list contains these values, I know you can use LINQ to make this query simple, I just can't think of an easy idea at the moment.

Thanks

My Solution worked...

 var value = pm.TableHeaders;

        List<string> nameFilters = new List<string>()
        {
            "Name",
            "Name2",
        };
        List<string> text = value.Select(x => x.Text).Where(columnName => columnName != "").ToList();

        return nameFilters.SequenceEqual(text);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM