1

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?

IOF
  • 251
  • 6
  • 18

2 Answers2

1

I believe instead of returning a list you can return a dictionary of lists with each document tile as key and list of all columns As value.

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

            foreach (var row in rows)
            {
               
                List<string> Col_value = new List<string>();
                IList<IWebElement> cols= row.FindElements(By.TagName("td"));
               foreach (var col in cols)
                 {
                     Col_value.Add( col.Text);
                 }
                fileNames.Add(row.Get_Attribute(“title”), Col_value);

            }
            return fileNames;

        }

Now you can iterate though dictionary to get list of all files upload and corroding column value for each file. Can see below link for same

What is the best way to iterate over a dictionary?

rahul rai
  • 2,260
  • 1
  • 7
  • 17
0

Instead of iterating over a List of strings for just fileNames, create a List of Files with properties as Name, size, modificationDateTime, numberOfDownloads, isDeleteable etc. List<Files> files = new List<Files>();

Then you can iterate over each row that is represented by a File from the files list.

DieGraueEminenz
  • 830
  • 2
  • 8
  • 18
  • Thanks for your reply! how would you assert this against an expected file list then? – IOF Sep 08 '20 at 05:59