如何使用Selenium WebDriver使用Web值声明十进制Excel值?

时间:2015-09-23 05:45:04

标签: c# excel selenium-webdriver decimal data-driven

Excel文件中提到的值为21.65,页面上显示的值相同。但是当脚本执行时,它将Excel值读为List<string> rowValue = new List<string> { }; var ExcelFilePath = "D:\\testexcel.xlsx"; Excel.Application xlApp = new Excel.Application(ExcelFilePath); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(ExcelFilePath); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; for (int i = 1; i <= rowCount; i++) { rowValue.Add(xlRange.Cells[i, j].Value2.ToString()); IWebElement element = driver.FindElement(By.Id(weight_field)); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element); string weight = driver.FindElement(By.Id(weight_field)).Text; if (mpuid == i) { Assert.AreEqual(weight,rowValue[0]); Console.WriteLine(" Expected Value: " + rowValue[0] + " is equal to Actual Value: " + weight); break; } rowValue.Clear(); } ,并且我的断言条件变为false。

{{1}}

2 个答案:

答案 0 :(得分:0)

在Excel文件中,将单元格类别更改为文本。

答案 1 :(得分:0)

根据This SO question的回答建议使用DataFormatter类。因为这将显示excel文件中显示的确切文本。