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

时间:2017-09-22 10:57:41

标签: c# selenium microsoft-edge streamwriter

我在Selenium中使用.net进行了一些自动化测试,并利用Streamwriter从Web应用程序中的表中复制数据。这在Chrome中工作得很好,因为我已经将Streamwriter从表中复制了整行并将其附加到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());
            }
        }

对此的任何帮助都将非常感激

1 个答案:

答案 0 :(得分:0)

更多谷歌搜索和利用Replace("\r", "")Replace("\n", "");做了伎俩