I've got some automated tests in Selenium using .net, and have utilised Streamwriter to copy data from a table in a web application. This works fine in Chrome, in that I've made the Streamwriter copy an entire row from a table and append that to a line in a csv file i.e...
DepartmentCodeDepartmentDescriptionTotalSpendTotalValue(%)SubjectivesLines
1Dep-100054Department-10005415282.403.1033861884
2Dep-100038Department-10003814282.292.9033962096
However in Edge the same code puts each cell on a new line...
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
The code for the Streamwriter is...
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());
}
}
Any help on this would be much appreciated
Bit more googling and utilising Replace("\r", "")
and Replace("\n", "");
did the trick