如何使用Selenium C#将HTML表格数据与预期的json数据进行比较?

时间:2019-06-05 07:17:05

标签: c# selenium-webdriver

我们需要使用Selenium C#将HTML Web表格数据与预期的json文件进行比较。

HTML WEB TABLE

期望的杰森:

"Players": 
[
  {
    "Name": "Jack",
    "Designation": "Batsmen",
    "Experience": 75
  },
  {
    "Name": "Raju",
    "Designation": "Allrounder",
    "Experience": 55
  },
  {
    "Name": "Manoj",
    "Designation": "Batsmen",
    "Experience": 7
  },
  {
    "Name": "Arjun",
    "Designation": "Allrounder",
    "Experience": 80
    },
    {
    "Name": "Jay",
    "Designation": "Bowler",
    "Experience": 25
    },
    {
    "Name": "Keyur",
    "Designation": "Bowler",
    "Experience": 73
    }     
  ]

我们要么需要将Web表格数据存储到json文件,然后比较这两个文件,要么直接将每个单元格与json文件进行比较。有什么建议吗?

var elemTable = element;
//ngDriver.FindElement(By.XPath(".//app-datagrid[1]//table[1]//tbody"));

List<IWebElement> lstTrElem = new List<IWebElement>(elemTable.FindElements(By.TagName("tr")));

foreach (var elemTr in lstTrElem)
{
    // Fetch the columns from a particuler row
    List<IWebElement> lstTdElem = new List<IWebElement>(elemTr.FindElements(By.TagName("td")));
    if (lstTdElem.Count > 0)
    {
        // Traverse each column
        foreach (var elemTd in lstTdElem)
        {                       
            String sValue = elemTd.GetAttribute("outerText");
           // Need to compare sValue with JSON file data
        }
    }
}

0 个答案:

没有答案