Streamwriter 将 table 个单元格放在 MS Egde 中的新行而不是同一行

Streamwriter putting table cells on new row in MS Egde instead of same row

我使用 .net 在 Selenium 中进行了一些自动化测试,并利用 Streamwriter 从 Web 应用程序中的 table 复制数据。这在 Chrome 中工作正常,因为我让 Streamwriter 从 table 复制整行并将其附加到 csv 文件中的一行,即...

DepartmentCodeDepartmentDescriptionTotalSpendTotalValue(%)SubjectivesLines
1Dep-100054Department-10005415282.403.1033861884
2Dep-100038Department-10003814282.292.9033962096

但是在 Edge 中,相同的代码将每个单元格放在一个新行上...

DepartmentCode
DepartmentDescription
TotalSpend
TotalValue(%)
Suppliers
Transactions
Directorates
CostCentres
Subjectives
Lines
1
Dep-100054
Department-100054
15282.40
3.10
3
3
8
6
18
84
2
Dep-100038
Department-100038
14282.29
2.90
3
3
9
6
20
96

Streamwriter 的代码是...

using (StreamWriter sw = new StreamWriter(actualDataFileLocation, false))
        {
            //Used for loop for number of rows
            for (int i = 1; i <= RowCount + 3; i++)
            {
                if (i == 2) // | i == 3)
                {
                    continue;
                }

                string line = string.Empty;
                string tableData = null;
                string finalXpath = null;

                if (i == 1 || i == 3)
                {
                    for (int j = 1; j <= ColCount; j++)
                    {
                        if (j == 1)
                        {
                            continue;
                        }
                        else
                        {
                            finalXpath = FirstPartHeader + i + SecondPartHeader + j + ThirdPartHeader;
                            tableData = driver.FindElement(By.XPath(finalXpath)).Text;
                            tableData = tableData.Replace(",", "");
                            tableData = tableData.Replace(" ", "");
                        }
                        line = line + string.Format(CultureInfo.CurrentCulture, "{0}", tableData);
                    }
                }
                else
                {
                    finalXpath = FirstPart + i + SecondPart;
                    tableData = driver.FindElement(By.XPath(finalXpath)).Text;
                    tableData = tableData.Replace(",", "");
                    tableData = tableData.Replace(" ", "");
                    line = line + string.Format(CultureInfo.CurrentCulture, "{0}", tableData);
                }
                sw.WriteLine(line.ToString());
            }
        }

如有任何帮助,我们将不胜感激

更多的谷歌搜索和利用 Replace("\r", "")Replace("\n", ""); 成功了