dimanche 6 septembre 2020

C# add only first column text in a table to a List

I have this table and I want to verify files have been uploaded successfully

enter image description here

I want to iterate through the first column and add file names to a list to assert against an expected list

This works but I am wondering how I can modify my method to be able to iterate through all columns and rows and I can add any column to the list. Basically make the method more useable and not use it just to verify file names but also to be able to verify other columns if needed

public List<string> ListofFilesUploaded()
            {
                IWebElement table = WebDriver.Driver.FindElement(By.XPath("//table[@id='files_list']//tbody"));
                IList<IWebElement> rows = table.FindElements(By.TagName("tr"));
                List<string> fileNames = new List<string>();

                foreach (var row in rows)
                {

                    fileNames.Add(row.Text.Split(' ').First());

                }
                return fileNames;

            }

enter image description here Does anyone have an idea how to enhance this solution or improve this?

Aucun commentaire:

Enregistrer un commentaire